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");
}
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)));
}
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());
}
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());
}
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);
}
Aggregations