Search in sources :

Example 61 with TimeZone

use of java.util.TimeZone in project WordPress-Android by wordpress-mobile.

the class DateTimeUtils method iso8601UTCFromDate.

/**
     * Given a {@link Date}, returns an ISO 8601-formatted String in UTC.
     */
public static String iso8601UTCFromDate(Date date) {
    if (date == null) {
        return "";
    }
    TimeZone tz = TimeZone.getTimeZone("UTC");
    DateFormat formatter = ISO8601_FORMAT.get();
    formatter.setTimeZone(tz);
    String iso8601date = formatter.format(date);
    // Use "+00:00" notation rather than "+0000" to be consistent with the WP.COM API
    return iso8601date.replace("+0000", "+00:00");
}
Also used : TimeZone(java.util.TimeZone) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat)

Example 62 with TimeZone

use of java.util.TimeZone in project spring-framework by spring-projects.

the class CookieLocaleResolver method setLocaleContext.

@Override
public void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext) {
    Locale locale = null;
    TimeZone timeZone = null;
    if (localeContext != null) {
        locale = localeContext.getLocale();
        if (localeContext instanceof TimeZoneAwareLocaleContext) {
            timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
        }
        addCookie(response, (locale != null ? toLocaleValue(locale) : "-") + (timeZone != null ? ' ' + timeZone.getID() : ""));
    } else {
        removeCookie(response);
    }
    request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, (locale != null ? locale : determineDefaultLocale(request)));
    request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME, (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) TimeZoneAwareLocaleContext(org.springframework.context.i18n.TimeZoneAwareLocaleContext)

Example 63 with TimeZone

use of java.util.TimeZone in project spring-framework by spring-projects.

the class CookieLocaleResolverTests method testSetLocaleContextToNull.

@Test
public void testSetLocaleContextToNull() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addPreferredLocale(Locale.TAIWAN);
    Cookie cookie = new Cookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME, Locale.UK.toString());
    request.setCookies(cookie);
    MockHttpServletResponse response = new MockHttpServletResponse();
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setLocaleContext(request, response, null);
    Locale locale = (Locale) request.getAttribute(CookieLocaleResolver.LOCALE_REQUEST_ATTRIBUTE_NAME);
    assertEquals(Locale.TAIWAN, locale);
    TimeZone timeZone = (TimeZone) request.getAttribute(CookieLocaleResolver.TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
    assertNull(timeZone);
    Cookie[] cookies = response.getCookies();
    assertEquals(1, cookies.length);
    Cookie localeCookie = cookies[0];
    assertEquals(CookieLocaleResolver.DEFAULT_COOKIE_NAME, localeCookie.getName());
    assertEquals("", localeCookie.getValue());
}
Also used : Cookie(javax.servlet.http.Cookie) Locale(java.util.Locale) TimeZone(java.util.TimeZone) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 64 with TimeZone

use of java.util.TimeZone in project spring-framework by spring-projects.

the class CookieLocaleResolverTests method testSetLocaleContextToNullWithDefault.

@Test
public void testSetLocaleContextToNullWithDefault() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addPreferredLocale(Locale.TAIWAN);
    Cookie cookie = new Cookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME, Locale.UK.toString());
    request.setCookies(cookie);
    MockHttpServletResponse response = new MockHttpServletResponse();
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setDefaultLocale(Locale.CANADA_FRENCH);
    resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+1"));
    resolver.setLocaleContext(request, response, null);
    Locale locale = (Locale) request.getAttribute(CookieLocaleResolver.LOCALE_REQUEST_ATTRIBUTE_NAME);
    assertEquals(Locale.CANADA_FRENCH, locale);
    TimeZone timeZone = (TimeZone) request.getAttribute(CookieLocaleResolver.TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
    assertEquals(TimeZone.getTimeZone("GMT+1"), timeZone);
    Cookie[] cookies = response.getCookies();
    assertEquals(1, cookies.length);
    Cookie localeCookie = cookies[0];
    assertEquals(CookieLocaleResolver.DEFAULT_COOKIE_NAME, localeCookie.getName());
    assertEquals("", localeCookie.getValue());
}
Also used : Cookie(javax.servlet.http.Cookie) Locale(java.util.Locale) TimeZone(java.util.TimeZone) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 65 with TimeZone

use of java.util.TimeZone in project spring-framework by spring-projects.

the class ServletRequestMethodArgumentResolverTests method zoneIdFromResolver.

@Test
public void zoneIdFromResolver() throws Exception {
    TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
    servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(Locale.US, timeZone));
    MethodParameter zoneIdParameter = new MethodParameter(method, 9);
    assertTrue("ZoneId not supported", resolver.supportsParameter(zoneIdParameter));
    Object result = resolver.resolveArgument(zoneIdParameter, null, webRequest, null);
    assertEquals("Invalid result", timeZone.toZoneId(), result);
}
Also used : TimeZone(java.util.TimeZone) FixedLocaleResolver(org.springframework.web.servlet.i18n.FixedLocaleResolver) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Aggregations

TimeZone (java.util.TimeZone)577 Date (java.util.Date)140 Calendar (java.util.Calendar)137 SimpleTimeZone (java.util.SimpleTimeZone)89 Test (org.junit.Test)85 SimpleDateFormat (java.text.SimpleDateFormat)69 Locale (java.util.Locale)69 GregorianCalendar (java.util.GregorianCalendar)56 ArrayList (java.util.ArrayList)32 DateFormat (java.text.DateFormat)24 ParseException (java.text.ParseException)23 IOException (java.io.IOException)20 Map (java.util.Map)15 HashSet (java.util.HashSet)13 PreparedStatement (java.sql.PreparedStatement)11 HashMap (java.util.HashMap)11 DateTimeZone (org.joda.time.DateTimeZone)11 Support_TimeZone (tests.support.Support_TimeZone)10 Resources (android.content.res.Resources)9 SQLException (java.sql.SQLException)9