use of java.util.GregorianCalendar in project j2objc by google.
the class CalendarTest method testAddOneDayAndOneDayOver30MinuteDstForwardAdds48Hours.
public void testAddOneDayAndOneDayOver30MinuteDstForwardAdds48Hours() {
Calendar calendar = new GregorianCalendar(AUSTRALIA_LORD_HOWE);
// 02:10 GMT+10:30
calendar.set(2011, 9, 1, 2, 10);
double hoursSinceEpoch = hoursSinceEpoch(calendar);
calendar.add(Calendar.DATE, 1);
calendar.add(Calendar.DATE, 1);
// The RI fails this test by returning 47.0. It adjusts for DST on both of the add() calls!
assertEquals(48.0, hoursSinceEpoch(calendar) - hoursSinceEpoch);
// 02:40 GMT+11:00; +48.0 hours
assertCalendarEquals(calendar, 2011, 9, 3, 2, 40);
}
use of java.util.GregorianCalendar in project j2objc by google.
the class CalendarTest method test_clear_45877_afternoon.
// https://code.google.com/p/android/issues/detail?id=45877
public void test_clear_45877_afternoon() {
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
// 3rd February 2016 12:32:40.000 America/Los_Angeles time.
cal.setTimeInMillis(1454531560000L);
checkClear(cal, 12, 72000000);
}
use of java.util.GregorianCalendar in project okhttp by square.
the class Cookie method parseExpires.
/** Parse a date as specified in RFC 6265, section 5.1.1. */
private static long parseExpires(String s, int pos, int limit) {
pos = dateCharacterOffset(s, pos, limit, false);
int hour = -1;
int minute = -1;
int second = -1;
int dayOfMonth = -1;
int month = -1;
int year = -1;
Matcher matcher = TIME_PATTERN.matcher(s);
while (pos < limit) {
int end = dateCharacterOffset(s, pos + 1, limit, true);
matcher.region(pos, end);
if (hour == -1 && matcher.usePattern(TIME_PATTERN).matches()) {
hour = Integer.parseInt(matcher.group(1));
minute = Integer.parseInt(matcher.group(2));
second = Integer.parseInt(matcher.group(3));
} else if (dayOfMonth == -1 && matcher.usePattern(DAY_OF_MONTH_PATTERN).matches()) {
dayOfMonth = Integer.parseInt(matcher.group(1));
} else if (month == -1 && matcher.usePattern(MONTH_PATTERN).matches()) {
String monthString = matcher.group(1).toLowerCase(Locale.US);
// Sneaky! jan=1, dec=12.
month = MONTH_PATTERN.pattern().indexOf(monthString) / 4;
} else if (year == -1 && matcher.usePattern(YEAR_PATTERN).matches()) {
year = Integer.parseInt(matcher.group(1));
}
pos = dateCharacterOffset(s, end + 1, limit, false);
}
// Convert two-digit years into four-digit years. 99 becomes 1999, 15 becomes 2015.
if (year >= 70 && year <= 99)
year += 1900;
if (year >= 0 && year <= 69)
year += 2000;
// seconds are not supported by this syntax.
if (year < 1601)
throw new IllegalArgumentException();
if (month == -1)
throw new IllegalArgumentException();
if (dayOfMonth < 1 || dayOfMonth > 31)
throw new IllegalArgumentException();
if (hour < 0 || hour > 23)
throw new IllegalArgumentException();
if (minute < 0 || minute > 59)
throw new IllegalArgumentException();
if (second < 0 || second > 59)
throw new IllegalArgumentException();
Calendar calendar = new GregorianCalendar(UTC);
calendar.setLenient(false);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis();
}
use of java.util.GregorianCalendar in project moshi by square.
the class Rfc3339DateJsonAdapterTest method newDate.
private Date newDate(int year, int month, int day, int hour, int minute, int second, int millis, int offset) {
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
calendar.set(year, month - 1, day, hour, minute, second);
calendar.set(Calendar.MILLISECOND, millis);
return new Date(calendar.getTimeInMillis() - TimeUnit.MINUTES.toMillis(offset));
}
use of java.util.GregorianCalendar in project rest.li by linkedin.
the class TestCustomTypesClient method testCalendarRefActionParam.
@Test
public void testCalendarRefActionParam() throws RemoteInvocationException {
ActionRequest<Integer> actionRequest = new CustomTypesRequestBuilders().actionCalendarAction().calendarParam(new GregorianCalendar()).build();
Response<Integer> response = getClient().sendRequest(actionRequest).getResponse();
Assert.assertEquals(response.getEntity().intValue(), Calendar.getInstance().get(Calendar.YEAR));
}
Aggregations