Search in sources :

Example 76 with GregorianCalendar

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);
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar)

Example 77 with GregorianCalendar

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);
}
Also used : GregorianCalendar(java.util.GregorianCalendar)

Example 78 with GregorianCalendar

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();
}
Also used : Matcher(java.util.regex.Matcher) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 79 with GregorianCalendar

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));
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 80 with GregorianCalendar

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));
}
Also used : CustomTypesRequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypesRequestBuilders) GregorianCalendar(java.util.GregorianCalendar) Test(org.testng.annotations.Test)

Aggregations

GregorianCalendar (java.util.GregorianCalendar)1278 Calendar (java.util.Calendar)603 Date (java.util.Date)377 Test (org.junit.Test)247 SimpleDateFormat (java.text.SimpleDateFormat)104 Timestamp (java.sql.Timestamp)54 ScheduleExpression (javax.ejb.ScheduleExpression)51 ArrayList (java.util.ArrayList)48 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)42 HashMap (java.util.HashMap)41 ParseException (java.text.ParseException)39 TimeZone (java.util.TimeZone)38 SimpleTimeZone (java.util.SimpleTimeZone)35 BigDecimal (java.math.BigDecimal)32 Date (java.sql.Date)30 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)28 SQLException (java.sql.SQLException)20 DateFormat (java.text.DateFormat)18 IOException (java.io.IOException)16 Map (java.util.Map)16