List of usage examples for org.joda.time DateTimeZone forOffsetMillis
public static DateTimeZone forOffsetMillis(int millisOffset)
From source file:com.moosemorals.weather.xml.LocationParser.java
License:Open Source License
private DateTimeZone readTimezone(XMLStreamReader parser) throws XMLStreamException, IOException { parser.require(XMLStreamReader.START_ELEMENT, NAMESPACE, "timezone"); DateTimeZone result = null;//from w w w. ja va2 s . c o m while (parser.next() != XMLStreamReader.END_ELEMENT) { if (parser.getEventType() != XMLStreamReader.START_ELEMENT) { continue; } switch (parser.getLocalName()) { case "offset": result = DateTimeZone.forOffsetMillis(Math.round(readFloatTag(parser, "offset") * 60 * 60 * 1000)); break; default: log.warn("Unrecognised tag {} in <timezone>", parser.getLocalName()); skipTag(parser); break; } } return result; }
From source file:com.niroshpg.android.earthquakemonitor.Utility.java
License:Apache License
/** * Helper method to convert the database representation of the date into something to display * to users. As classy and polished a user experience as "20140102" is, we can do better. * * @param context Context to use for resource localization * @param dateStr The db formatted date string, expected to be of the form specified * in Utility.DATE_FORMAT * @return a user-friendly representation of the date. */// w w w.j a v a2 s . c om public static String getFriendlyDayString(Context context, String dateStr) { // The day string for earthquake events uses the following logic: // For today: "Today, June 8" // For tomorrow: "Tomorrow" // For the next 5 days: "Wednesday" (just the day name) // For all days after that: "Mon Jun 8" Date todayDate = new Date(); String todayStr = EarthQuakeDataContract.getDbDateString(todayDate); DateTime inputDateUTC = DateTimeFormat.forPattern(DATETIME_FORMAT).withZone(DateTimeZone.UTC) .parseDateTime(dateStr); // currentTimeZone.inDaylightTime() DateTime inputDateCurrentTZ = inputDateUTC .toDateTime(DateTimeZone.forOffsetMillis(currentTimeZone.getRawOffset())); // If the date we're building the String for is today's date, the format // is "Today, June 24" if (todayStr.equals(dateStr)) { String today = context.getString(R.string.today); int formatId = R.string.format_full_friendly_date; return String.format(context.getString(formatId, today, getFormattedMonthDay(context, dateStr))); } else { DateTimeFormatter shortenedDateTimeFormat = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss"); return inputDateCurrentTZ.toString(shortenedDateTimeFormat); // } } }
From source file:com.qatickets.domain.UserProfile.java
License:Open Source License
public DateTimeZone getDateTimeZone() { return DateTimeZone.forOffsetMillis(this.getTimezoneInMs()); }
From source file:com.robwilliamson.healthyesther.App.java
License:Open Source License
@Override public void onCreate() { super.onCreate(); JodaTimeAndroid.init(this); DateTimeZone.setDefault(DateTimeZone.forOffsetMillis(TimeZone.getDefault().getRawOffset())); if (BuildConfig.DEBUG) { HealthDbHelper.sDebug = true;/*from www . j av a 2 s . co m*/ } sUiThreadId = Thread.currentThread().getId(); sInstance = this; TimingManager.INSTANCE.applicationCreated(getApplicationContext()); }
From source file:com.springsource.greenhouse.home.DateTimeZoneHandlerInterceptor.java
License:Apache License
private DateTimeZone getTimeZone(HttpServletRequest request) { Integer millisOffset = getMillisOffset(request); if (millisOffset != null) { try {//from w ww . j a v a2s . c om return DateTimeZone.forOffsetMillis(millisOffset); } catch (IllegalArgumentException e) { return DateTimeZone.getDefault(); } } else { return DateTimeZone.getDefault(); } }
From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java
License:Open Source License
/** * Helper method that will return TimeZone object from a given request. It reads timezoneOffset parameter from the * request and based on offset value, it will create a TimeZone object * * @param servletRequest Servlet Request having timezoneOffset * @return TimeZone object. If the request does not have timezoneOffset, it will return server's TimeZone *//*from w w w . j a va2 s . c om*/ public static TimeZone getRequestTimezone(WebRequest servletRequest) { String timezoneOffset = servletRequest.getParameter("timezoneOffset"); TimeZone tz = TimeZone.getDefault(); try { if (timezoneOffset != null) { // Convert time zone offset from minutes to milliseconds // JavaScript time zone offset needs to be multiplied by -1 // in order to feed it to JODA time zone call tz = DateTimeZone.forOffsetMillis(Integer.parseInt(timezoneOffset) * 60 * -1000).toTimeZone(); } } catch (Exception e) { e.printStackTrace(); } return tz; }
From source file:io.coala.xml.XmlUtil.java
License:Apache License
/** * @param date a JAXP {@link XMLGregorianCalendar} * @return/*from w w w . jav a 2 s . co m*/ */ public static DateTime toDateTime(final XMLGregorianCalendar date) { final DateTimeZone timeZone = date.getTimezone() == DatatypeConstants.FIELD_UNDEFINED ? DateTimeZone.getDefault() : DateTimeZone.forOffsetMillis(date.getTimezone() * 60 * 1000); return new DateTime(date.getYear(), date.getMonth(), date.getDay(), date.getHour(), date.getMinute(), date.getSecond(), date.getMillisecond(), timeZone); }
From source file:io.warp10.script.mapper.MapperDayOfMonth.java
License:Apache License
public MapperDayOfMonth(String name, Object timezone) { super(name);/* w w w . j a v a 2 s . c o m*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperDayOfWeek.java
License:Apache License
public MapperDayOfWeek(String name, Object timezone) { super(name);/*from w ww. ja va 2s .c o m*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperHourOfDay.java
License:Apache License
public MapperHourOfDay(String name, Object timezone) { super(name);/*from w w w . j a va 2 s .c o m*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }