public DateTimeDatasetVersionFinder(FileSystem fs, Config config) {
    super(fs);
    Preconditions.checkArgument(
        config.hasPath(DATE_TIME_PATTERN_KEY),
        "Missing required property " + DATE_TIME_PATTERN_KEY);
    String pattern = config.getString(DATE_TIME_PATTERN_KEY);

    if (config.hasPath(OPTIONAL_GLOB_PATTERN_TIMEZONE_KEY)) {
      this.globPattern = new Path(config.getString(OPTIONAL_GLOB_PATTERN_TIMEZONE_KEY));
    } else {
      this.globPattern = new Path(pattern.replaceAll("[^/]+", "*"));
    }

    LOGGER.debug(
        String.format(
            "Setting timezone for patthern: %s. By default it is %s",
            pattern, DEFAULT_DATE_TIME_PATTERN_TIMEZONE));

    if (config.hasPath(DATE_TIME_PATTERN_TIMEZONE_KEY)) {
      this.formatter =
          DateTimeFormat.forPattern(pattern)
              .withZone(DateTimeZone.forID(config.getString(DATE_TIME_PATTERN_TIMEZONE_KEY)));
    } else {
      this.formatter =
          DateTimeFormat.forPattern(pattern)
              .withZone(DateTimeZone.forID(DEFAULT_DATE_TIME_PATTERN_TIMEZONE));
    }

    this.datePartitionPattern = pattern;
  }
  @Test
  public void testToStringForTimeZone_fromApiDate() {
    Assert.assertEquals(
        stringDateTime1, DateTimes.toStringForTimeZone(apiDateTime1, TIME_ZONE_ID1));
    Assert.assertEquals(
        stringDateTime2, DateTimes.toStringForTimeZone(apiDateTime2, TIME_ZONE_ID2));
    Assert.assertEquals(
        stringDateTime3, DateTimes.toStringForTimeZone(apiDateTime3, TIME_ZONE_ID3));

    Assert.assertEquals(
        stringDateTime1,
        DateTimes.toStringForTimeZone(
            DateTimes.toDateTime(jodaDateTime1.withZone(DateTimeZone.forID(TIME_ZONE_ID2))),
            TIME_ZONE_ID1));
    Assert.assertEquals(
        stringDateTime2,
        DateTimes.toStringForTimeZone(
            DateTimes.toDateTime(jodaDateTime2.withZone(DateTimeZone.forID(TIME_ZONE_ID1))),
            TIME_ZONE_ID2));
    Assert.assertEquals(
        stringDateTime3,
        DateTimes.toStringForTimeZone(
            DateTimes.toDateTime(jodaDateTime3.withZone(DateTimeZone.forID(TIME_ZONE_ID1))),
            TIME_ZONE_ID3));
  }
Пример #3
0
  public void test_dataFlowCheck() throws Exception {
    DateTimeZone tz1 = DateTimeZone.forID("Europe/Athens");
    tz1.getID();

    Long n = System.currentTimeMillis();
    DateTimeZone tz2 = DateTimeZone.forID("Europe/Amsterdam");
    tz2.getName(n, null);
  }
Пример #4
0
 public void test_inLocale() throws Exception {
   Assert.assertEquals(
       "Heure d'Europe centrale",
       DateTimeZone.forID("Europe/Prague")
           .getName(
               DateTimeOperations.convert(
                   new DateTime(2008, 1, 1, 12, 0, 0, 0, DateTimeZone.forID("Europe/Prague"))),
               Locale.FRENCH));
 }
Пример #5
0
 public void test_timeZoneFromString() throws Exception {
   Long nn = System.currentTimeMillis();
   String tz = "Europe/Berlin";
   DateTimeZone tzz = DateTimeZone.forID(tz);
   DateTime inberl = DateTimeOperations.convert(nn, DateTimeZone.forID(tz));
   Assert.assertEquals(inberl, DateTimeOperations.convert(nn, tzz));
   Assert.assertEquals("Europe/Berlin", tzz.getID());
   Assert.assertEquals("Europe/Moscow", DateTimeZone.forID("Europe/Moscow").getID());
 }
  @Test(groups = "fast")
  public void testCalculateBCDWithSubscriptionDateNotInUTC() throws Exception {
    // Test to verify the computations don't rely implicitly on UTC
    final DateTimeZone accountTimeZone = DateTimeZone.forID("Asia/Tokyo");
    final DateTime startDate = new DateTime("2012-07-16T21:17:03.000Z", DateTimeZone.forID("HST"));
    final int bcdLocal = 17;

    verifyBCDCalculation(accountTimeZone, startDate, bcdLocal);
  }
  public void testTimeUnitRoundingDST() {
    Rounding tzRounding;
    // testing savings to non savings switch
    DateTimeZone cet = DateTimeZone.forID("CET");
    tzRounding = Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(cet).build();
    assertThat(
        tzRounding.round(time("2014-10-26T01:01:01", cet)),
        isDate(time("2014-10-26T01:00:00+02:00"), cet));
    assertThat(
        tzRounding.nextRoundingValue(time("2014-10-26T01:00:00", cet)),
        isDate(time("2014-10-26T02:00:00+02:00"), cet));
    assertThat(
        tzRounding.nextRoundingValue(time("2014-10-26T02:00:00", cet)),
        isDate(time("2014-10-26T02:00:00+01:00"), cet));

    // testing non savings to savings switch
    tzRounding = Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(cet).build();
    assertThat(
        tzRounding.round(time("2014-03-30T01:01:01", cet)),
        isDate(time("2014-03-30T01:00:00+01:00"), cet));
    assertThat(
        tzRounding.nextRoundingValue(time("2014-03-30T01:00:00", cet)),
        isDate(time("2014-03-30T03:00:00", cet), cet));
    assertThat(
        tzRounding.nextRoundingValue(time("2014-03-30T03:00:00", cet)),
        isDate(time("2014-03-30T04:00:00", cet), cet));

    // testing non savings to savings switch (America/Chicago)
    DateTimeZone chg = DateTimeZone.forID("America/Chicago");
    Rounding tzRounding_utc =
        Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(DateTimeZone.UTC).build();
    assertThat(
        tzRounding.round(time("2014-03-09T03:01:01", chg)),
        isDate(time("2014-03-09T03:00:00", chg), chg));

    Rounding tzRounding_chg = Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(chg).build();
    assertThat(
        tzRounding_chg.round(time("2014-03-09T03:01:01", chg)),
        isDate(time("2014-03-09T03:00:00", chg), chg));

    // testing savings to non savings switch 2013 (America/Chicago)
    assertThat(
        tzRounding_utc.round(time("2013-11-03T06:01:01", chg)),
        isDate(time("2013-11-03T06:00:00", chg), chg));
    assertThat(
        tzRounding_chg.round(time("2013-11-03T06:01:01", chg)),
        isDate(time("2013-11-03T06:00:00", chg), chg));

    // testing savings to non savings switch 2014 (America/Chicago)
    assertThat(
        tzRounding_utc.round(time("2014-11-02T06:01:01", chg)),
        isDate(time("2014-11-02T06:00:00", chg), chg));
    assertThat(
        tzRounding_chg.round(time("2014-11-02T06:01:01", chg)),
        isDate(time("2014-11-02T06:00:00", chg), chg));
  }
Пример #8
0
 public void test_westernHemisphereTime() throws Exception {
   Long yesterday =
       DateTimeOperations.convert(
           (new DateTime(2009, 7, 23, 13, 18, 20, 0, DateTimeZone.forID("UTC"))));
   Assert.assertEquals(
       DateTimeOperations.print(
           yesterday, DateTimeFormat.shortTime(), null, DateTimeZone.forID("America/New_York")),
       DateTimeOperations.print(
           (DateTimeArithmetics.minus(yesterday, Period.hours(11))),
           DateTimeFormat.shortTime(),
           null,
           DateTimeZone.forID("Asia/Bangkok")));
 }
Пример #9
0
 public void test_londonAndMoscowShortTime() throws Exception {
   Long current = System.currentTimeMillis();
   Assert.assertEquals(
       DateTimeOperations.print(
           current,
           DateTimeFormat.shortTime(),
           new Locale("ru", "RU", ""),
           DateTimeZone.forID("Europe/London")),
       DateTimeOperations.print(
           (DateTimeArithmetics.minus(current, Period.hours(3))),
           DateTimeFormat.shortTime(),
           new Locale("ru", "RU", ""),
           DateTimeZone.forID("Europe/Moscow")));
 }
Пример #10
0
 public void test_timeZoneFromStringLiteral() throws Exception {
   Long thisMoment = System.currentTimeMillis();
   Assert.assertEquals(
       DateTimeOperations.print(
           thisMoment,
           (MainFormatTable.INSTANCE).getFormatter("date/time"),
           null,
           DateTimeZone.forID("Europe/Moscow")),
       DateTimeOperations.print(
           thisMoment,
           (MainFormatTable.INSTANCE).getFormatter("date/time"),
           null,
           DateTimeZone.forID("Europe/Moscow")));
 }
Пример #11
0
 public void test_timeZoneFromVariable() throws Exception {
   String zone = "Europe/Berlin";
   Long thisMoment = System.currentTimeMillis();
   Assert.assertEquals(
       DateTimeOperations.print(
           thisMoment,
           (MainFormatTable.INSTANCE).getFormatter("date/time"),
           null,
           DateTimeZone.forID(zone)),
       DateTimeOperations.print(
           thisMoment,
           (MainFormatTable.INSTANCE).getFormatter("date/time"),
           null,
           DateTimeZone.forID("Europe/Berlin")));
 }
Пример #12
0
/** @author geoffc */
public class Filename {

  private static DateTimeZone tz = DateTimeZone.forID("UTC");
  private static DateTimeFormatter yearFormat = DateTimeFormat.forPattern("YYYY").withZone(tz);
  private static DateTimeFormatter shortYearFormat = DateTimeFormat.forPattern("YY").withZone(tz);
  private static DateTimeFormatter dayOfYearFormat = DateTimeFormat.forPattern("DDD").withZone(tz);
  private static DateTimeFormatter monthFormat = DateTimeFormat.forPattern("MM").withZone(tz);
  private static DateTimeFormatter dayOfMonthFormat = DateTimeFormat.forPattern("dd").withZone(tz);
  private static DateTimeFormatter hourFormat = DateTimeFormat.forPattern("HH").withZone(tz);
  private static DateTimeFormatter minuteFormat = DateTimeFormat.forPattern("mm").withZone(tz);
  private static DateTimeFormatter secondFormat = DateTimeFormat.forPattern("ss").withZone(tz);

  public static String makeFilename(String mask, NSCL nscl, DateTime begin) {

    String name = mask;

    // GeoNet types: .D .T (01-ACE) .L (01-LOG)
    // from http://www.seiscomp3.org/wiki/doc/applications/slarchive
    // type	description
    // 'D'   Waveform data
    // 'E'   Detection data
    // 'L'   Log data
    // 'T'   Timing data
    // 'C'   Calibration data
    // 'R'   Response data
    // 'O'   Opaque data
    // e.g. 2011/NZ/WVZ/HHE.D/NZ.WVZ.10.HHE.D.2011.017
    // Note the %z to remove underscores.
    name = name.replaceAll("%SDS", "%z%y/%n/%s/%c.D/%n.%s.%l.%c.D.%y.%j");

    name = name.replaceAll("%N", nscl.toString().replaceAll(" ", "_"));
    name = name.replaceAll("%n", nscl.getNetwork().replaceAll(" ", "_"));
    name = name.replaceAll("%s", nscl.getStation().replaceAll(" ", "_"));
    name = name.replaceAll("%c", nscl.getChannel().replaceAll(" ", "_"));
    name = name.replaceAll("%l", nscl.getLocation().replaceAll(" ", "_"));

    name = name.replaceAll("%y", yearFormat.print(begin));
    name = name.replaceAll("%Y", shortYearFormat.print(begin));

    name = name.replaceAll("%j", dayOfYearFormat.print(begin));
    name = name.replaceAll("%J", Integer.toString(SeedUtil.toJulian(begin.toGregorianCalendar())));

    name = name.replaceAll("%M", monthFormat.print(begin));
    name = name.replaceAll("%d", dayOfMonthFormat.print(begin));
    name = name.replaceAll("%D", dayOfMonthFormat.print(begin));
    name = name.replaceAll("%h", hourFormat.print(begin));
    name = name.replaceAll("%m", minuteFormat.print(begin));
    name = name.replaceAll("%S", secondFormat.print(begin));
    if (name.indexOf("%z") >= 0) {
      name = name.replaceAll("%z", "");
      name = name.replaceAll("_", "");
    }
    return name;
  }

  public static String makeFilename(String mask, NSCL nscl, MiniSeed ms) {

    return makeFilename(mask, nscl, new DateTime(ms.getGregorianCalendar().getTimeInMillis(), tz));
  }
}
Пример #13
0
  @Test
  public void dates_should_be_serialized_in_ISO_8601_format() {
    setupNegativeContains("some_id");
    when(httpClient.put(anyString(), anyString()))
        .thenReturn(
            HttpResponseStub.valueOf(201, "{\"ok\":true,\"id\":\"some_id\",\"rev\":\"123D123\"}"));

    DateTime dt = new DateTime(2010, 4, 25, 20, 11, 24, 555, DateTimeZone.forID("+00:00"));
    Date d = dt.toDate();
    System.out.println(d);
    DateDoc dd = new DateDoc();
    dd.setId("some_id");
    dd.setDateTime(dt);
    dd.setDate(dt.toDate());

    dbCon.create(dd);

    ArgumentCaptor<String> ac = ArgumentCaptor.forClass(String.class);
    verify(httpClient).put(eq("/test_db/some_id"), ac.capture());
    String json = ac.getValue();
    assertEqualJson("dates.json", json);

    when(httpClient.get("/test_db/some_id")).thenReturn(HttpResponseStub.valueOf(201, json));

    DateDoc deserialized = dbCon.get(DateDoc.class, dd.getId());
    assertEquals(dt, deserialized.getDateTime());
    assertEquals(d, deserialized.getDate());
  }
Пример #14
0
  /**
   * Extract time-zone information from a zoneinfo (Olson database) ID and saves them in the
   * TimeZoneHelper fields.
   *
   * @param id the time zone ID according to the zoneinfo (Olson) database
   * @param from the start of the relevant time interval for the generation of transitions (an
   *     istant expressed as a long)
   * @param to the end of the relevant time interval for the generation of transitions (an istant
   *     expressed as a long)
   */
  protected void processID(String id, long from, long to) {

    DateTimeZone tz = DateTimeZone.forID(id);
    if (name == null) { // The name could have been set already using TZID
      // and in this case it is important not to change it
      name = id; // The Olson ID is perfect as a unique name
    }
    basicOffset = tz.getStandardOffset(from);
    transitions.clear();

    if (!tz.isFixed()) {

      long oldFrom = from;
      from = fixFrom(tz, basicOffset, oldFrom);

      // @todo Consider case when to go beyond last transition (cycle
      // could become endless)
      while (tz.getStandardOffset(to) != tz.getOffset(to)) {
        to = tz.nextTransition(to);
      }

      while ((from <= to) && (oldFrom != from)) {
        transitions.add(new TimeZoneTransition(tz.getOffset(from), from, id));
        oldFrom = from;
        from = tz.nextTransition(oldFrom);
      }
    }
  }
  /** special test for DST switch from #9491 */
  public void testAmbiguousHoursAfterDSTSwitch() {
    Rounding tzRounding;
    final DateTimeZone tz = DateTimeZone.forID("Asia/Jerusalem");
    tzRounding = Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2014-10-26T00:30:00+03:00")),
        isDate(time("2014-10-26T00:00:00+03:00"), tz));
    assertThat(
        tzRounding.round(time("2014-10-26T01:30:00+03:00")),
        isDate(time("2014-10-26T01:00:00+03:00"), tz));
    // the utc date for "2014-10-25T03:00:00+03:00" and "2014-10-25T03:00:00+02:00" is the same,
    // local time turns back 1h here
    assertThat(time("2014-10-26T03:00:00+03:00"), isDate(time("2014-10-26T02:00:00+02:00"), tz));
    assertThat(
        tzRounding.round(time("2014-10-26T01:30:00+02:00")),
        isDate(time("2014-10-26T01:00:00+02:00"), tz));
    assertThat(
        tzRounding.round(time("2014-10-26T02:30:00+02:00")),
        isDate(time("2014-10-26T02:00:00+02:00"), tz));

    // Day interval
    tzRounding = Rounding.builder(DateTimeUnit.DAY_OF_MONTH).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2014-11-11T17:00:00", tz)),
        isDate(time("2014-11-11T00:00:00", tz), tz));
    // DST on
    assertThat(
        tzRounding.round(time("2014-08-11T17:00:00", tz)),
        isDate(time("2014-08-11T00:00:00", tz), tz));
    // Day of switching DST on -> off
    assertThat(
        tzRounding.round(time("2014-10-26T17:00:00", tz)),
        isDate(time("2014-10-26T00:00:00", tz), tz));
    // Day of switching DST off -> on
    assertThat(
        tzRounding.round(time("2015-03-27T17:00:00", tz)),
        isDate(time("2015-03-27T00:00:00", tz), tz));

    // Month interval
    tzRounding = Rounding.builder(DateTimeUnit.MONTH_OF_YEAR).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2014-11-11T17:00:00", tz)),
        isDate(time("2014-11-01T00:00:00", tz), tz));
    // DST on
    assertThat(
        tzRounding.round(time("2014-10-10T17:00:00", tz)),
        isDate(time("2014-10-01T00:00:00", tz), tz));

    // Year interval
    tzRounding = Rounding.builder(DateTimeUnit.YEAR_OF_CENTURY).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2014-11-11T17:00:00", tz)),
        isDate(time("2014-01-01T00:00:00", tz), tz));

    // Two timestamps in same year and different timezone offset ("Double buckets" issue - #9491)
    tzRounding = Rounding.builder(DateTimeUnit.YEAR_OF_CENTURY).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2014-11-11T17:00:00", tz)),
        isDate(tzRounding.round(time("2014-08-11T17:00:00", tz)), tz));
  }
  /**
   * Special test for intervals that don't fit evenly into rounding interval. In this case, when
   * interval crosses DST transition point, rounding in local time can land in a DST gap which
   * results in wrong UTC rounding values.
   */
  public void testIntervalRounding_NotDivisibleInteval() {
    DateTimeZone tz = DateTimeZone.forID("CET");
    long interval = TimeUnit.MINUTES.toMillis(14);
    Rounding rounding = new Rounding.TimeIntervalRounding(interval, tz);

    assertThat(
        rounding.round(time("2016-03-27T01:41:00+01:00")),
        isDate(time("2016-03-27T01:30:00+01:00"), tz));
    assertThat(
        rounding.round(time("2016-03-27T01:51:00+01:00")),
        isDate(time("2016-03-27T01:44:00+01:00"), tz));
    assertThat(
        rounding.round(time("2016-03-27T01:59:00+01:00")),
        isDate(time("2016-03-27T01:58:00+01:00"), tz));
    assertThat(
        rounding.round(time("2016-03-27T03:05:00+02:00")),
        isDate(time("2016-03-27T03:00:00+02:00"), tz));
    assertThat(
        rounding.round(time("2016-03-27T03:12:00+02:00")),
        isDate(time("2016-03-27T03:08:00+02:00"), tz));
    assertThat(
        rounding.round(time("2016-03-27T03:25:00+02:00")),
        isDate(time("2016-03-27T03:22:00+02:00"), tz));
    assertThat(
        rounding.round(time("2016-03-27T03:39:00+02:00")),
        isDate(time("2016-03-27T03:36:00+02:00"), tz));
  }
 /**
  * test DST start with offset not fitting interval, e.g. Asia/Kathmandu adding 15min on
  * 1986-01-01T00:00:00 the interval from 1986-01-01T00:15:00+05:45 to 1986-01-01T00:20:00+05:45 to
  * only be 5min long
  */
 public void testTimeInterval_Kathmandu_DST_Start() {
   long interval = TimeUnit.MINUTES.toMillis(20);
   DateTimeZone tz = DateTimeZone.forID("Asia/Kathmandu");
   Rounding rounding = new TimeIntervalRounding(interval, tz);
   assertThat(
       rounding.round(time("1985-12-31T23:55:00+05:30")),
       isDate(time("1985-12-31T23:40:00+05:30"), tz));
   assertThat(
       rounding.round(time("1986-01-01T00:16:00+05:45")),
       isDate(time("1986-01-01T00:15:00+05:45"), tz));
   assertThat(
       time("1986-01-01T00:15:00+05:45") - time("1985-12-31T23:40:00+05:30"),
       equalTo(TimeUnit.MINUTES.toMillis(20)));
   assertThat(
       rounding.round(time("1986-01-01T00:26:00+05:45")),
       isDate(time("1986-01-01T00:20:00+05:45"), tz));
   assertThat(
       time("1986-01-01T00:20:00+05:45") - time("1986-01-01T00:15:00+05:45"),
       equalTo(TimeUnit.MINUTES.toMillis(5)));
   assertThat(
       rounding.round(time("1986-01-01T00:46:00+05:45")),
       isDate(time("1986-01-01T00:40:00+05:45"), tz));
   assertThat(
       time("1986-01-01T00:40:00+05:45") - time("1986-01-01T00:20:00+05:45"),
       equalTo(TimeUnit.MINUTES.toMillis(20)));
 }
  /**
   * test DST end with interval rounding CET: 25 October 2015, 03:00:00 clocks were turned backward
   * 1 hour to 25 October 2015, 02:00:00 local standard time
   */
  public void testTimeIntervalCET_DST_End() {
    long interval = TimeUnit.MINUTES.toMillis(20);
    DateTimeZone tz = DateTimeZone.forID("CET");
    Rounding rounding = new TimeIntervalRounding(interval, tz);

    assertThat(
        rounding.round(time("2015-10-25T01:55:00+02:00")),
        isDate(time("2015-10-25T01:40:00+02:00"), tz));
    assertThat(
        rounding.round(time("2015-10-25T02:15:00+02:00")),
        isDate(time("2015-10-25T02:00:00+02:00"), tz));
    assertThat(
        rounding.round(time("2015-10-25T02:35:00+02:00")),
        isDate(time("2015-10-25T02:20:00+02:00"), tz));
    assertThat(
        rounding.round(time("2015-10-25T02:55:00+02:00")),
        isDate(time("2015-10-25T02:40:00+02:00"), tz));
    // after DST shift
    assertThat(
        rounding.round(time("2015-10-25T02:15:00+01:00")),
        isDate(time("2015-10-25T02:00:00+01:00"), tz));
    assertThat(
        rounding.round(time("2015-10-25T02:35:00+01:00")),
        isDate(time("2015-10-25T02:20:00+01:00"), tz));
    assertThat(
        rounding.round(time("2015-10-25T02:55:00+01:00")),
        isDate(time("2015-10-25T02:40:00+01:00"), tz));
    assertThat(
        rounding.round(time("2015-10-25T03:15:00+01:00")),
        isDate(time("2015-10-25T03:00:00+01:00"), tz));
  }
  private void generateTimeComparisons(List<String> timeZoneIds) {
    mDisplayLists.clear();

    // Cache timezone objects
    DateTimeZone[] timeZones = new DateTimeZone[timeZoneIds.size()];
    for (int i = 0; i < timeZoneIds.size(); i++) {
      timeZones[i] = DateTimeZone.forID(timeZoneIds.get(i));
    }

    // Round current time down to the hour
    DateTime dateTime =
        new DateTime().withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);

    // format to local date/time (shorten for more comparisons)
    mDateTimeFormatter =
        timeZones.length < 3 ? DateTimeFormat.shortDateTime() : DateTimeFormat.shortTime();

    // Iterate over the next n hours
    for (int i = 0; i < DISPLAY_HOURS; i++) {
      List<String> displayList = new ArrayList<String>();
      for (DateTimeZone dateTimeZone : timeZones) {
        displayList.add(dateTime.withZone(dateTimeZone).toString(mDateTimeFormatter));
      }
      mDisplayLists.add(displayList);
      dateTime = dateTime.plusHours(1);
    }
  }
Пример #20
0
  public static void testTimeZone() {

    System.out.println("演示时区");

    String format = "yyyy-MM-dd HH:mm:ss zZZ";

    // DateTime的毫秒即System的毫秒,即1970到现在的UTC的毫秒数.
    System.out.println(new DateTime().getMillis() + " " + System.currentTimeMillis());

    // 将日期按默认时区打印
    DateTime fooDate = new DateTime(1978, 6, 1, 12, 10, 8, 0);
    System.out.println(
        fooDate.toString(format) + " " + fooDate.getMillis()); // "1978-06-01 12:10:08"

    // 将日期按UTC时区打印
    DateTime zoneWithUTC = fooDate.withZone(DateTimeZone.UTC);
    System.out.println(
        zoneWithUTC.toString(format)
            + " "
            + zoneWithUTC.getMillis()); // "1978-06-01 04:10:08", sameMills

    // 按不同的时区分析字符串,得到不同的时间
    String dateString = "1978-06-01 12:10:08";
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");

    DateTime parserResult1 =
        fmt.withZone(DateTimeZone.forID("US/Pacific")).parseDateTime(dateString);
    DateTime parserResult2 = fmt.withZone(DateTimeZone.UTC).parseDateTime(dateString);

    System.out.println(parserResult1.toString(format) + " " + parserResult1.getMillis());
    System.out.println(parserResult2.toString(format) + " " + parserResult2.getMillis());
  }
  public void testTimezone() throws Exception {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    String queryAsString =
        "{\n"
            + "    \"query_string\":{\n"
            + "        \"time_zone\":\"Europe/Paris\",\n"
            + "        \"query\":\""
            + DATE_FIELD_NAME
            + ":[2012 TO 2014]\"\n"
            + "    }\n"
            + "}";
    QueryBuilder<?> queryBuilder = parseQuery(queryAsString);
    assertThat(queryBuilder, instanceOf(QueryStringQueryBuilder.class));
    QueryStringQueryBuilder queryStringQueryBuilder = (QueryStringQueryBuilder) queryBuilder;
    assertThat(queryStringQueryBuilder.timeZone(), equalTo(DateTimeZone.forID("Europe/Paris")));

    try {
      queryAsString =
          "{\n"
              + "    \"query_string\":{\n"
              + "        \"time_zone\":\"This timezone does not exist\",\n"
              + "        \"query\":\""
              + DATE_FIELD_NAME
              + ":[2012 TO 2014]\"\n"
              + "    }\n"
              + "}";
      parseQuery(queryAsString);
      fail("we expect a ParsingException as we are providing an unknown time_zome");
    } catch (IllegalArgumentException e) {
      // We expect this one
    }
  }
 private static List<DateTimeZone> createZones() {
   final List<DateTimeZone> zones = new ArrayList<DateTimeZone>();
   for (final String zone : DateTimeZone.getAvailableIDs()) {
     zones.add(DateTimeZone.forID(zone));
   }
   return zones;
 }
 private void setDefaultTimeZone() {
   String dtzStr = pc.getProperties().getProperty("pig.datetime.default.tz");
   if (dtzStr != null && dtzStr.length() > 0) {
     currentDTZ = DateTimeZone.getDefault();
     DateTimeZone.setDefault(DateTimeZone.forID(dtzStr));
   }
 }
Пример #24
0
  @Test(groups = "slow")
  public void testUpdate() throws Exception {
    final Account account = createTestAccount(1);
    accountDao.create(account, internalCallContext);

    final AccountData accountData =
        new MockAccountBuilder(account)
            .migrated(false)
            .isNotifiedForInvoices(false)
            .timeZone(DateTimeZone.forID("Australia/Darwin"))
            .locale("FR-CA")
            .build();

    final Account updatedAccount = new DefaultAccount(account.getId(), accountData);
    accountDao.update(updatedAccount, internalCallContext);

    final Account savedAccount =
        accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);

    assertNotNull(savedAccount);
    assertEquals(savedAccount.getName(), updatedAccount.getName());
    assertEquals(savedAccount.getEmail(), updatedAccount.getEmail());
    assertEquals(savedAccount.getPaymentMethodId(), updatedAccount.getPaymentMethodId());
    assertEquals(savedAccount.getBillCycleDay(), updatedAccount.getBillCycleDay());
    assertEquals(savedAccount.getFirstNameLength(), updatedAccount.getFirstNameLength());
    assertEquals(savedAccount.getTimeZone(), updatedAccount.getTimeZone());
    assertEquals(savedAccount.getLocale(), updatedAccount.getLocale());
    assertEquals(savedAccount.getAddress1(), updatedAccount.getAddress1());
    assertEquals(savedAccount.getAddress2(), updatedAccount.getAddress2());
    assertEquals(savedAccount.getCity(), updatedAccount.getCity());
    assertEquals(savedAccount.getStateOrProvince(), updatedAccount.getStateOrProvince());
    assertEquals(savedAccount.getCountry(), updatedAccount.getCountry());
    assertEquals(savedAccount.getPostalCode(), updatedAccount.getPostalCode());
    assertEquals(savedAccount.getPhone(), updatedAccount.getPhone());
  }
Пример #25
0
  private Account createTestAccount(final int billCycleDay, final String phone) {
    final String thisKey = "test" + UUID.randomUUID().toString();
    final String lastName = UUID.randomUUID().toString();
    final String thisEmail = "*****@*****.**" + " " + UUID.randomUUID();
    final String firstName = "Bob";
    final String name = firstName + " " + lastName;
    final String locale = "EN-US";
    final DateTimeZone timeZone = DateTimeZone.forID("America/Los_Angeles");
    final int firstNameLength = firstName.length();

    return new DefaultAccount(
        UUID.randomUUID(),
        thisKey,
        thisEmail,
        name,
        firstNameLength,
        Currency.USD,
        new DefaultBillCycleDay(billCycleDay, billCycleDay),
        UUID.randomUUID(),
        timeZone,
        locale,
        null,
        null,
        null,
        null,
        null,
        null,
        null, // add null address fields
        phone,
        false,
        false);
  }
Пример #26
0
 @Test(groups = "fast")
 public void testNextBCDShouldNotBeInThePast() throws Exception {
   final LocalDate from = new LocalDate("2012-07-16");
   final LocalDate to =
       InvoiceDateUtils.calculateBillingCycleDateOnOrAfter(
           from, DateTimeZone.forID("Pacific/Pitcairn"), 15);
   Assert.assertEquals(to, new LocalDate("2012-08-15"));
 }
Пример #27
0
 public void test_westernHemisphereDate() throws Exception {
   Long yesterday =
       DateTimeOperations.convert(
           (new DateTime(2009, 7, 23, 13, 18, 20, 0, DateTimeZone.forID("UTC"))));
   Assert.assertFalse(
       (DateTimeOperations.print(
               yesterday,
               DateTimeFormat.fullDate(),
               Locale.US,
               DateTimeZone.forID("America/New_York")))
           .equals(
               DateTimeOperations.print(
                   (DateTimeArithmetics.plus(yesterday, Period.hours(22))),
                   DateTimeFormat.fullDate(),
                   Locale.US,
                   DateTimeZone.forID("Asia/Bangkok"))));
 }
  @Test(groups = "fast")
  public void testCalculateBCDWithTimeZoneCEST() throws Exception {
    final DateTimeZone accountTimeZone = DateTimeZone.forID("Europe/Paris");
    final DateTime startDateUTC = new DateTime("2012-07-16T21:17:03.000Z", DateTimeZone.UTC);
    final int bcdLocal = 16;

    verifyBCDCalculation(accountTimeZone, startDateUTC, bcdLocal);
  }
 String buildInternalId(
     final DateTime messageTimeStamp, final BigDecimal accountId, final Order order) {
   final DateTime dtLondon = messageTimeStamp.withZone(DateTimeZone.forID("Europe/London"));
   final String date = DATE_TIME_FORMATTER.print(dtLondon);
   final long nextIncrement = atomicLong.getAndIncrement();
   return String.format(
       "%s_%s_%s_%s_%s",
       order.getCashier(), order.getProductId(), accountId.toPlainString(), date, nextIncrement);
 }
  public void execute(JobExecutionContext context) throws JobExecutionException {
    EventWindowData.loadInitialData();

    DateTimeZone zone = DateTimeZone.forID("America/New_York");
    Chronology gregorianJuian = GJChronology.getInstance(zone);

    List<String> serverIds = new ArrayList<>();

    for (ServerID servId : ServerID.values()) {
      serverIds.add(servId.getUid() + "");
    }

    // System.out.println("Starting LowPriority Thread retrieve "+this.toString()+" at "+new
    // DateTime(gregorianJuian));

    for (GolemEvent eventId : GolemEvent.values()) {
      queryEvent(gregorianJuian, serverIds, eventId.uid(), lowPriorityEventData);
    }

    for (DredgeEvent eventId : DredgeEvent.values()) {
      queryEvent(gregorianJuian, serverIds, eventId.uid(), lowPriorityEventData);
    }

    for (HarathiChestEvent eventId : HarathiChestEvent.values()) {
      queryEvent(gregorianJuian, serverIds, eventId.uid(), lowPriorityEventData);
    }

    for (FoulBearEvent eventId : FoulBearEvent.values()) {
      queryEvent(gregorianJuian, serverIds, eventId.uid(), lowPriorityEventData);
    }

    for (HydraQueenEvent eventId : HydraQueenEvent.values()) {
      queryEvent(gregorianJuian, serverIds, eventId.uid(), lowPriorityEventData);
    }

    for (FireShamanEnum eventId : FireShamanEnum.values()) {
      queryEvent(gregorianJuian, serverIds, eventId.uid(), lowPriorityEventData);
    }

    for (KarkaEvent eventId : KarkaEvent.values()) {
      queryEvent(gregorianJuian, serverIds, eventId.uid(), lowPriorityEventData);
    }

    // System.out.println("Ended LowPriority Thread retrieve "+this.toString()+" at "+new
    // DateTime(gregorianJuian));

    GolemEvent.formatGolemString(lowPriorityEventData);
    DredgeEvent.formatDredgeString(lowPriorityEventData);
    FoulBearEvent.formatOgreString(lowPriorityEventData);
    HarathiChestEvent.formatHarathiString(lowPriorityEventData);
    HydraQueenEvent.formatHydraString(lowPriorityEventData);
    FireShamanEnum.formatShamanString(lowPriorityEventData);
    KarkaEvent.formatKarkaString(lowPriorityEventData);

    // System.out.println("Ended LowPriority Thread formating "+this.toString()+" at "+new
    // DateTime(gregorianJuian));
  }