コード例 #1
0
ファイル: RubyTime.java プロジェクト: rizkyrukmana/jruby
  protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) {
    Ruby runtime = recv.getRuntime();

    DateTime dt = new DateTime(DateTimeZone.UTC);

    byte[] fromAsBytes = null;
    fromAsBytes = from.convertToString().getBytes();
    if (fromAsBytes.length != 8) {
      throw runtime.newTypeError("marshaled time format differ");
    }
    int p = 0;
    int s = 0;
    for (int i = 0; i < 4; i++) {
      p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i);
    }
    for (int i = 4; i < 8; i++) {
      s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4));
    }
    boolean utc = false;
    if ((p & (1 << 31)) == 0) {
      dt = dt.withMillis(p * 1000L);
      time.setUSec((s & 0xFFFFF) % 1000);
    } else {
      p &= ~(1 << 31);
      utc = ((p >>> 30 & 0x1) == 0x1);
      dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900);
      dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1);
      dt = dt.withDayOfMonth(((p >>> 5) & 0x1F));
      dt = dt.withHourOfDay((p & 0x1F));
      dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F));
      dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F));
      // marsaling dumps usec, not msec
      dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000);
      time.setUSec((s & 0xFFFFF) % 1000);
    }
    time.setDateTime(dt);
    if (!utc) time.localtime();

    from.getInstanceVariables().copyInstanceVariablesInto(time);
    return time;
  }
コード例 #2
0
ファイル: VtGateIT.java プロジェクト: henryanand/vitess
  @Test
  public void testDateFieldTypes() throws Exception {
    DateTime dt = DateTime.now().minusDays(2).withMillisOfSecond(0);
    Util.insertRows(testEnv, 10, 1, dt);
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    Query allRowsQuery =
        new QueryBuilder("select * from vtgate_test", testEnv.keyspace, "master")
            .setKeyspaceIds(testEnv.getAllKeyspaceIds())
            .build();
    Row row = vtgate.execute(allRowsQuery).next();
    Assert.assertTrue(dt.equals(row.getDateTime("timestamp_col")));
    Assert.assertTrue(dt.equals(row.getDateTime("datetime_col")));
    Assert.assertTrue(
        dt.withHourOfDay(0)
            .withMinuteOfHour(0)
            .withSecondOfMinute(0)
            .equals(row.getDateTime("date_col")));
    Assert.assertTrue(
        dt.withYear(1970).withMonthOfYear(1).withDayOfMonth(1).equals(row.getDateTime("time_col")));

    vtgate.close();
  }
コード例 #3
0
  public void generate(File namesFile, int days, File outFolder) throws IOException {
    if (outFolder.exists()) {
      FileUtils.deleteDirectory(outFolder);
    }
    outFolder.mkdirs();

    if (!namesFile.exists()) {
      throw new IllegalArgumentException("Provided names file doesn't exist (" + namesFile + ")");
    }

    List<String> names = Files.readLines(namesFile, Charset.forName("UTF-8"));

    DateTime today = new DateTime();
    DateTime someDaysBefore = today.minusDays(days);

    someDaysBefore = someDaysBefore.withMinuteOfHour(0);
    someDaysBefore = someDaysBefore.withSecondOfMinute(0);

    while (someDaysBefore.isBefore(today)) {
      for (int hour = 0; hour < 24; hour++) {

        someDaysBefore = someDaysBefore.withHourOfDay(hour);

        File currentFile = new File(outFolder, "pagecounts-" + format.print(someDaysBefore));
        BufferedWriter writer = new BufferedWriter(new FileWriter(currentFile));

        for (String name : names) {
          int pageviews = (int) (Math.random() * 10000) + 1;
          writer.write("en " + name + " " + pageviews + " 0" + "\n");
        }

        writer.close();
      }
      someDaysBefore = someDaysBefore.plusDays(1);
    }
  }