List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:com.sos.hibernate.classes.UtcTimeHelper.java
License:Apache License
public static Date convertTimeZonesToDate(String fromTimeZone, String toTimeZone, DateTime fromDateTime) { if (fromDateTime == null) { return null; }//from ww w . j a v a2 s. c o m DateTimeZone fromZone = DateTimeZone.forID(fromTimeZone); DateTimeZone toZone = DateTimeZone.forID(toTimeZone); DateTime dateTime = new DateTime(fromDateTime); dateTime = dateTime.withZoneRetainFields(fromZone); DateTime toDateTime = new DateTime(dateTime).withZone(toZone); DateTimeFormatter oFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'H:mm:ss.SSSZ"); DateTimeFormatter oFormatter2 = DateTimeFormat.forPattern("yyyy-MM-dd H:mm:ss.ss"); DateTime newDate = oFormatter.withOffsetParsed().parseDateTime(toDateTime.toString()); try { return new SimpleDateFormat("yyyy-MM-dd H:mm:ss.ss") .parse(oFormatter2.withZone(toZone).print(newDate.getMillis())); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:com.springsource.greenhouse.events.JdbcEventRepository.java
License:Apache License
@Transactional public List<EventSession> findSessionsOnDay(Long eventId, LocalDate day, Long attendeeId) { DateTimeZone eventTimeZone = DateTimeZone.forID( jdbcTemplate.queryForObject("select timezone from Event where id = ?", String.class, eventId)); DateTime dayStart = day.toDateTimeAtStartOfDay(eventTimeZone); DateTime dayEnd = dayStart.plusDays(1); return jdbcTemplate.query(SELECT_SESSIONS_ON_DAY, eventSessionMapper.list(), attendeeId, eventId, dayStart.toDate(), dayEnd.toDate()); }
From source file:com.springsource.greenhouse.events.JdbcEventRepository.java
License:Apache License
private static DateTime adjustEventTimeToUTC(Timestamp timestamp, String eventTimeZone) { MutableDateTime mutableDateTime = new DateTime(timestamp).toMutableDateTime(); mutableDateTime.setZoneRetainFields(DateTimeZone.forID(eventTimeZone)); DateTime utcAdjustedDateTime = mutableDateTime.toDateTime().toDateTime(DateTimeZone.UTC); return utcAdjustedDateTime; }
From source file:com.squarespace.template.plugins.PluginDateUtils.java
License:Apache License
public static void humanizeDate(long instantMs, long baseMs, String tzId, boolean showSeconds, StringBuilder buf) {/*from w ww. ja v a 2s .co m*/ DateTimeZone timeZone = DateTimeZone.forID(tzId); int offset = timeZone.getOffset(instantMs); Duration delta = new Duration(baseMs - instantMs + offset); int days = (int) delta.getStandardDays(); int years = (int) Math.floor(days / 365.0); if (years > 0) { humanizeDatePlural(years, DatePartType.YEAR, buf); return; } int months = (int) Math.floor(days / 30.0); if (months > 0) { humanizeDatePlural(months, DatePartType.MONTH, buf); return; } int weeks = (int) Math.floor(days / 7.0); if (weeks > 0) { humanizeDatePlural(weeks, DatePartType.WEEK, buf); return; } if (days > 0) { humanizeDatePlural(days, DatePartType.DAY, buf); return; } int hours = (int) delta.getStandardHours(); if (hours > 0) { humanizeDatePlural(hours, DatePartType.HOUR, buf); return; } int mins = (int) delta.getStandardMinutes(); if (mins > 0) { humanizeDatePlural(mins, DatePartType.MINUTE, buf); return; } int secs = (int) delta.getStandardSeconds(); if (showSeconds) { humanizeDatePlural(secs, DatePartType.SECOND, buf); return; } buf.append("less than a minute ago"); }
From source file:com.squarespace.template.plugins.PluginDateUtils.java
License:Apache License
public static boolean sameDay(long instant1, long instant2, String tzName) { DateTimeZone zone = null;//from ww w .j a v a 2 s.co m try { zone = DateTimeZone.forID(tzName); } catch (IllegalArgumentException e) { zone = DateTimeZone.getDefault(); } DateTime date1 = new DateTime(instant1, zone); DateTime date2 = new DateTime(instant2, zone); return (date1.year().get() == date2.year().get()) && (date1.monthOfYear().get() == date2.monthOfYear().get()) && (date1.dayOfMonth().get() == date2.dayOfMonth().get()); }
From source file:com.squarespace.template.plugins.PluginDateUtils.java
License:Apache License
/** * Takes a strftime()-compatible format string and outputs the properly formatted date. */// w ww . ja v a 2s .c o m public static void formatDate(Locale locale, String fmt, long instant, String tzName, StringBuilder buf) { DateTimeZone zone = null; try { zone = DateTimeZone.forID(tzName); } catch (IllegalArgumentException e) { zone = DateTimeZone.getDefault(); } DateTime date = new DateTime(instant, zone); int index = 0; int len = fmt.length(); while (index < len) { char c1 = fmt.charAt(index); index++; if (c1 != '%' || index == len) { buf.append(c1); continue; } char c2 = fmt.charAt(index); switch (c2) { case 'A': buf.append(date.dayOfWeek().getAsText(locale)); break; case 'a': buf.append(date.dayOfWeek().getAsShortText(locale)); break; case 'B': buf.append(date.monthOfYear().getAsText(locale)); break; case 'b': buf.append(date.monthOfYear().getAsShortText(locale)); break; case 'C': leftPad(date.centuryOfEra().get(), '0', 2, buf); break; case 'c': formatAggregate(DateTimeAggregate.FULL, locale, date, buf); break; case 'D': formatAggregate(DateTimeAggregate.MMDDYY, locale, date, buf); break; case 'd': leftPad(date.dayOfMonth().get(), '0', 2, buf); break; case 'e': leftPad(date.dayOfMonth().get(), ' ', 2, buf); break; case 'F': formatAggregate(DateTimeAggregate.YYYYMMDD, locale, date, buf); break; case 'G': buf.append(date.year().get()); break; case 'g': leftPad(date.yearOfCentury().get(), '0', 2, buf); break; case 'H': leftPad(date.hourOfDay().get(), '0', 2, buf); break; case 'h': buf.append(date.monthOfYear().getAsShortText(locale)); break; case 'I': leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf); break; case 'j': leftPad(date.dayOfYear().get(), '0', 3, buf); break; case 'k': leftPad(date.get(DateTimeFieldType.clockhourOfDay()), ' ', 2, buf); break; case 'l': leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), ' ', 2, buf); break; case 'M': leftPad(date.minuteOfHour().get(), '0', 2, buf); break; case 'm': leftPad(date.monthOfYear().get(), '0', 2, buf); break; case 'n': buf.append('\n'); break; case 'P': buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "am" : "pm"); break; case 'p': buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM"); break; case 'R': formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf); break; case 'S': leftPad(date.secondOfMinute().get(), '0', 2, buf); break; case 's': buf.append(instant / 1000); break; case 't': buf.append('\t'); break; case 'T': // Equivalent of %H:%M:%S formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf); buf.append(':'); leftPad(date.secondOfMinute().get(), '0', 2, buf); break; case 'U': // TODO: fix week-of-year number leftPad(date.weekOfWeekyear().get(), '0', 2, buf); break; case 'u': buf.append(date.dayOfWeek().get()); break; case 'V': // TODO: fix week-of-year number leftPad(date.weekOfWeekyear().get(), '0', 2, buf); break; case 'v': // Equivalent of %e-%b-%Y leftPad(date.dayOfMonth().get(), ' ', 2, buf); buf.append('-'); buf.append(date.monthOfYear().getAsShortText()); buf.append('-'); buf.append(date.getYear()); break; case 'W': // TODO: fix week-of-year number break; case 'w': buf.append(date.dayOfWeek().get()); break; case 'X': formatAggregate(DateTimeAggregate.HHMMSSP, locale, date, buf); break; case 'x': formatAggregate(DateTimeAggregate.MMDDYYYY, locale, date, buf); break; case 'Y': buf.append(date.getYear()); break; case 'y': leftPad(date.getYearOfCentury(), '0', 2, buf); break; case 'Z': // Note: Joda's nameKey happens to be the same as the shortName. Making // this change to workaround Joda https://github.com/JodaOrg/joda-time/issues/288 buf.append(zone.getNameKey(date.getMillis())); break; case 'z': int offset = date.getZone().getOffset(instant) / 60000; int hours = (int) Math.floor(offset / 60); int minutes = (hours * 60) - offset; if (offset < 0) { buf.append('-'); } leftPad(Math.abs(hours), '0', 2, buf); leftPad(Math.abs(minutes), '0', 2, buf); break; default: // no match, emit literals. buf.append(c1).append(c2); } index++; } }
From source file:com.thinkbiganalytics.DateTimeUtil.java
License:Apache License
public static Date convertToUTC(Date date) { DateTime time = new DateTime(date.getTime()); DateTimeZone dtZone = DateTimeZone.forID("UTC"); DateTime utc = time.withZone(dtZone); return utc.toDate(); }
From source file:com.thinkbiganalytics.DateTimeUtil.java
License:Apache License
public static DateTime convertToUTC(DateTime date) { DateTimeZone dtZone = DateTimeZone.forID("UTC"); DateTime utc = date.withZone(dtZone); return new DateTime(utc); }
From source file:com.thinkbiganalytics.DateTimeUtil.java
License:Apache License
public static DateTime convertToUTC(Long time) { DateTimeZone dtZone = DateTimeZone.forID("UTC"); DateTime date = new DateTime(time); DateTime utc = date.withZone(dtZone); return new DateTime(utc); }
From source file:com.thoughtworks.studios.journey.jql.transforms.TimeFloor.java
License:Open Source License
@Override public JQLValue apply(JQLValue value, String... params) { TimeGroupingInterval interval = TimeGroupingInterval.valueOf(params[0].toUpperCase()); DateTimeZone timezone = DateTimeZone.UTC; if (params.length > 1) { timezone = DateTimeZone.forID(params[1]); }//from w ww .ja va 2s . c o m if (value == NullValue.instance) { return value; } SingleValue v = (SingleValue) value; Long ts = (Long) v.getWrapped(); return Values.wrapSingle(interval.floor(ts, timezone)); }