@Test(groups = "fast")
  public void test2WithAccountInUtcMinus8() throws EntitlementApiException {

    final DateTime initialNow = new DateTime(2013, 8, 22, 22, 07, 01, 0, DateTimeZone.UTC);
    clock.setTime(initialNow);

    final LocalDate inputDate = new LocalDate(2013, 8, 22);

    final DateTimeZone timeZoneUtcMinus8 = DateTimeZone.forOffsetHours(-8);
    Mockito.when(account.getTimeZone()).thenReturn(timeZoneUtcMinus8);

    // We also use a reference time of 16, 48, 0 -> DateTime in UTC will be (2013, 8, 23, 00, 48, 0)
    // which:
    // * is greater than now
    // * with a inputLocalDate in the account timezone which is today
    //
    // => Code will round to now to not end up in the future
    //
    final DateTime refererenceDateTime = new DateTime(2013, 8, 22, 16, 48, 0, DateTimeZone.UTC);
    final DateTime targetDate =
        dateHelper.fromLocalDateAndReferenceTime(
            inputDate, refererenceDateTime, internalCallContext);

    final DateTime now = clock.getUTCNow();
    Assert.assertTrue(initialNow.compareTo(targetDate) <= 0);
    Assert.assertTrue(targetDate.compareTo(now) <= 0);
  }
예제 #2
0
 @Test
 public void testUpdatedDate() {
   Issue issue = new Issue(null, Utils.getTestIssue());
   assertEquals(
       new DateTime(2013, 10, 9, 22, 24, 55, 961, DateTimeZone.forOffsetHours(1)).toDate(),
       issue.getUpdatedDate());
 }
  @Test
  public void testRoundingWithTimeZone() {
    MutableDateTime time = new MutableDateTime(DateTimeZone.UTC);
    time.setZone(DateTimeZone.forOffsetHours(-2));
    time.setRounding(time.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC);
    utcTime.setRounding(utcTime.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    time.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));

    assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-03T00:00:00.000Z"));
    // the time is on the 2nd, and utcTime is on the 3rd, but, because time already encapsulates
    // time zone, the millis diff is not 24, but 22 hours
    assertThat(
        time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));

    time.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    assertThat(time.toString(), equalTo("2009-02-03T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-04T00:00:00.000Z"));
    assertThat(
        time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
  }
예제 #4
0
 @Test
 public void testCreatedDate() {
   Issue issue = new Issue(null, Utils.getTestIssue());
   assertEquals(
       new DateTime(2013, 9, 29, 20, 16, 19, 854, DateTimeZone.forOffsetHours(1)).toDate(),
       issue.getCreatedDate());
 }
 @Test
 public void getLocalPositiveOffsetUppercaseMaxDateTime() throws Exception {
   DateTime result = client.datetimes().getLocalPositiveOffsetUppercaseMaxDateTime();
   DateTime expected =
       new DateTime(9999, 12, 31, 23, 59, 59, 999, DateTimeZone.forOffsetHours(14))
           .toDateTime(DateTimeZone.UTC);
   Assert.assertEquals(expected, result);
 }
 @Test
 public void getLocalNegativeOffsetMinDateTime() throws Exception {
   DateTime result = client.datetimes().getLocalNegativeOffsetMinDateTime();
   DateTime expected =
       new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeZone.forOffsetHours(-14))
           .toDateTime(DateTimeZone.UTC);
   Assert.assertEquals(expected, result);
 }
 @Test
 public void getOverflowDate() throws Exception {
   DateTime result = client.datetimes().getOverflow();
   // 9999-12-31T23:59:59.999-14:000
   DateTime expected =
       new DateTime(9999, 12, 31, 23, 59, 59, 999, DateTimeZone.forOffsetHours(-14));
   expected = expected.toDateTime(DateTimeZone.UTC);
   Assert.assertEquals(expected, result);
 }
  @Test(groups = "fast")
  public void testIsBeforeOrEqualsToday() {

    clock.setTime(new DateTime(2013, 8, 7, 3, 28, 10, 0, DateTimeZone.UTC));
    final DateTimeZone timeZoneUtcMinus8 = DateTimeZone.forOffsetHours(-8);

    final DateTime inputDateEquals = new DateTime(2013, 8, 6, 23, 28, 10, 0, timeZoneUtcMinus8);
    // Check that our input date is greater than now
    assertTrue(inputDateEquals.compareTo(clock.getUTCNow()) > 0);
    // And yet since the LocalDate match the function returns true
    assertTrue(dateHelper.isBeforeOrEqualsToday(inputDateEquals, timeZoneUtcMinus8));
  }
  public void testTimeRounding() {
    // hour unit
    DateTimeZone tz = DateTimeZone.forOffsetHours(-2);
    Rounding tzRounding = Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(tz).build();
    assertThat(tzRounding.round(0), equalTo(0L));
    assertThat(tzRounding.nextRoundingValue(0L), equalTo(TimeValue.timeValueHours(1L).getMillis()));

    assertThat(
        tzRounding.round(time("2009-02-03T01:01:01")), isDate(time("2009-02-03T01:00:00"), tz));
    assertThat(
        tzRounding.nextRoundingValue(time("2009-02-03T01:00:00")),
        isDate(time("2009-02-03T02:00:00"), tz));
  }
  /** test TimeIntervalRounding, (interval &lt; 12h) with time zone shift */
  public void testTimeIntervalRounding() {
    DateTimeZone tz = DateTimeZone.forOffsetHours(-1);
    Rounding tzRounding = Rounding.builder(TimeValue.timeValueHours(6)).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2009-02-03T00:01:01")),
        isDate(time("2009-02-02T19:00:00.000Z"), tz));
    assertThat(
        tzRounding.nextRoundingValue(time("2009-02-02T19:00:00.000Z")),
        isDate(time("2009-02-03T01:00:00.000Z"), tz));

    assertThat(
        tzRounding.round(time("2009-02-03T13:01:01")),
        isDate(time("2009-02-03T13:00:00.000Z"), tz));
    assertThat(
        tzRounding.nextRoundingValue(time("2009-02-03T13:00:00.000Z")),
        isDate(time("2009-02-03T19:00:00.000Z"), tz));
  }
  @Test(groups = "fast")
  public void testWithAccountInUtcMinus8() throws EntitlementApiException {

    final LocalDate inputDate = new LocalDate(2013, 8, 7);
    clock.setDay(inputDate.plusDays(3));

    final DateTimeZone timeZoneUtcMinus8 = DateTimeZone.forOffsetHours(-8);
    Mockito.when(account.getTimeZone()).thenReturn(timeZoneUtcMinus8);

    // We also use a reference time of 1, 28, 10, 0 -> DateTime in accountTimeZone will be (2013, 8,
    // 7, 1, 28, 10)
    final DateTime refererenceDateTime = new DateTime(2013, 1, 1, 1, 28, 10, 0, DateTimeZone.UTC);
    final DateTime targetDate =
        dateHelper.fromLocalDateAndReferenceTime(
            inputDate, refererenceDateTime, internalCallContext);

    // And so that datetime in UTC becomes expectedDate below
    final DateTime expectedDate = new DateTime(2013, 8, 7, 9, 28, 10, 0, DateTimeZone.UTC);
    Assert.assertEquals(targetDate, expectedDate);
  }
  public void testDayRounding() {
    int timezoneOffset = -2;
    Rounding tzRounding =
        Rounding.builder(DateTimeUnit.DAY_OF_MONTH)
            .timeZone(DateTimeZone.forOffsetHours(timezoneOffset))
            .build();
    assertThat(
        tzRounding.round(0), equalTo(0L - TimeValue.timeValueHours(24 + timezoneOffset).millis()));
    assertThat(
        tzRounding.nextRoundingValue(0L - TimeValue.timeValueHours(24 + timezoneOffset).millis()),
        equalTo(0L - TimeValue.timeValueHours(timezoneOffset).millis()));

    DateTimeZone tz = DateTimeZone.forID("-08:00");
    tzRounding = Rounding.builder(DateTimeUnit.DAY_OF_MONTH).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2012-04-01T04:15:30Z")), isDate(time("2012-03-31T08:00:00Z"), tz));

    tzRounding = Rounding.builder(DateTimeUnit.MONTH_OF_YEAR).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2012-04-01T04:15:30Z")), equalTo(time("2012-03-01T08:00:00Z")));

    // date in Feb-3rd, but still in Feb-2nd in -02:00 timezone
    tz = DateTimeZone.forID("-02:00");
    tzRounding = Rounding.builder(DateTimeUnit.DAY_OF_MONTH).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2009-02-03T01:01:01")), isDate(time("2009-02-02T02:00:00"), tz));
    assertThat(
        tzRounding.nextRoundingValue(time("2009-02-02T02:00:00")),
        isDate(time("2009-02-03T02:00:00"), tz));

    // date in Feb-3rd, also in -02:00 timezone
    tzRounding = Rounding.builder(DateTimeUnit.DAY_OF_MONTH).timeZone(tz).build();
    assertThat(
        tzRounding.round(time("2009-02-03T02:01:01")), isDate(time("2009-02-03T02:00:00"), tz));
    assertThat(
        tzRounding.nextRoundingValue(time("2009-02-03T02:00:00")),
        isDate(time("2009-02-04T02:00:00"), tz));
  }
예제 #13
0
파일: App.java 프로젝트: ndong211/bo
 @Override
 public void onCreate() {
   super.onCreate();
   sINSTANCE = this;
   DateTimeZone.forOffsetHours(8);
 }
 @Test
 public void putLocalPositiveOffsetMaxDateTime() throws Exception {
   DateTime body = new DateTime(9999, 12, 31, 23, 59, 59, 999, DateTimeZone.forOffsetHours(14));
   client.datetimes().putLocalPositiveOffsetMaxDateTime(body);
 }
 @Test
 public void putLocalNegativeOffsetMinDateTime() throws Exception {
   DateTime body = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeZone.forOffsetHours(-14));
   client.datetimes().putLocalNegativeOffsetMinDateTime(body);
 }