List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:com.yahoo.bard.webservice.data.PreResponseDeserializer.java
License:Apache License
/** * Get a time zone instance for the specified time zone id. * * @param timeZoneId the ID of the datetime zone, null means default * @param systemTimeZone timeZone of the system * * @return the DateTimeZone object for the ID * * @throws DeserializationException When timeZoneId is unable to recognize *//*from w ww .j ava 2 s . c om*/ private DateTimeZone generateTimezone(String timeZoneId, DateTimeZone systemTimeZone) throws DeserializationException { if (timeZoneId == null) { return systemTimeZone; } try { return DateTimeZone.forID(timeZoneId); } catch (IllegalArgumentException e) { String msg = ErrorMessageFormat.UNKNOWN_TIMEZONE_ID.format(timeZoneId); LOG.error(msg, e); throw new DeserializationException(msg, e); } }
From source file:com.yahoo.bard.webservice.web.apirequest.ApiRequestImpl.java
License:Apache License
/** * Get the timezone for the request./*from ww w . j a v a2 s. co m*/ * * @param timeZoneId String of the TimeZone ID * @param systemTimeZone TimeZone of the system to use if there is no timeZoneId * * @return the request's TimeZone */ protected DateTimeZone generateTimeZone(String timeZoneId, DateTimeZone systemTimeZone) { try (TimedPhase timer = RequestLog.startTiming("generatingTimeZone")) { if (timeZoneId == null) { return systemTimeZone; } try { return DateTimeZone.forID(timeZoneId); } catch (IllegalArgumentException ignored) { LOG.debug(INVALID_TIME_ZONE.logFormat(timeZoneId)); throw new BadApiRequestException(INVALID_TIME_ZONE.format(timeZoneId)); } } }
From source file:com.yahoo.bard.webservice.web.DataApiRequest.java
License:Apache License
/** * Get the timezone for the request./*from w w w. j av a2 s . c o m*/ * * @param timeZoneId String of the TimeZone ID * @param systemTimeZone TimeZone of the system to use if there is no timeZoneId * * @return the request's TimeZone */ private DateTimeZone generateTimeZone(String timeZoneId, DateTimeZone systemTimeZone) { if (timeZoneId == null) { return systemTimeZone; } try { return DateTimeZone.forID(timeZoneId); } catch (IllegalArgumentException ignored) { LOG.debug(INVALID_TIME_ZONE.logFormat(timeZoneId)); throw new BadApiRequestException(INVALID_TIME_ZONE.format(timeZoneId)); } }
From source file:com.yourmediashelf.fedora.util.DateUtility.java
License:Open Source License
/** * Parses lexical representations of xsd:dateTimes, e.g. * "2010-01-31T14:21:03.001Z". Fractional seconds and timezone offset are * optional./*w w w .ja v a2 s. c o m*/ * * <p>Note: fractional seconds are only supported to three digits of * precision.</p> * * @param input * an XML Schema 1.1 dateTime * @return a DateTime representing the input * @see "http://www.w3.org/TR/xmlschema11-2/#dateTime" */ public static DateTime parseXSDDateTime(String input) { Matcher m = XSD_DATETIME.matcher(input); if (!m.find()) { throw new IllegalArgumentException(input + " is not a valid XML Schema 1.1 dateTime."); } int year = Integer.parseInt(m.group(1)); int month = Integer.parseInt(m.group(3)); int day = Integer.parseInt(m.group(4)); int hour = 0, minute = 0, second = 0, millis = 0; boolean hasEndOfDayFrag = m.group(11) != null; if (!hasEndOfDayFrag) { hour = Integer.parseInt(m.group(6)); minute = Integer.parseInt(m.group(7)); second = Integer.parseInt(m.group(8)); // Parse fractional seconds // m.group(9), if not null/empty should be Strings such as ".5" or // ".050" which convert to 500 and 50, respectively. if (m.group(9) != null && !m.group(9).isEmpty()) { // parse as Double as a quick hack to drop trailing 0s. // e.g. ".0500" becomes 0.05 double d = Double.parseDouble(m.group(9)); // Something like the following would allow for int-sized // precision, but joda-time 1.6 only supports millis (i.e. <= 999). // see: org.joda.time.field.FieldUtils.verifyValueBounds // int digits = String.valueOf(d).length() - 2; // fractionalSeconds = (int) (d * Math.pow(10, digits)); millis = (int) (d * 1000); } } DateTimeZone zone = null; if (m.group(13) != null) { String tmp = m.group(13); if (tmp.equals("Z")) { tmp = "+00:00"; } zone = DateTimeZone.forID(tmp); } DateTime dt = new DateTime(year, month, day, hour, minute, second, millis, zone); if (hasEndOfDayFrag) { return dt.plusDays(1); } return dt; }
From source file:controllers.Api.Statistic.java
License:Open Source License
public static Result getStatisticDayStats(Integer id) { // Variables/* w ww . j ava2 s . c om*/ Integer index = 0, slideHour, yesterdayHour; DateTime slideDayTime, yesterdayDayTime; List<models.StatisticDay> statisticsDay = models.StatisticDay.find.where().eq("slide.slide_id", id).order() .asc("updateTime").findList(); Iterator<models.StatisticDay> statisticsDayIterator = statisticsDay.iterator(); // Yesterday Time Calc yesterdayDayTime = (new DateTime()).withZone(DateTimeZone.forID(session("timezone"))); yesterdayDayTime = yesterdayDayTime.minusHours(23); yesterdayHour = yesterdayDayTime.getHourOfDay(); // 0 Liste initialisieren List<Integer> statisticsDayReturn = Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // Iterate List while (statisticsDayIterator.hasNext()) { models.StatisticDay statisticDayObject = statisticsDayIterator.next(); // Slide Time Calc slideDayTime = statisticDayObject.updateTime; slideDayTime = slideDayTime.withZone(DateTimeZone.forID(session("timezone"))); slideHour = slideDayTime.getHourOfDay(); // Because of long to int exceptionhandling try { if (slideHour == yesterdayHour) { index = statisticsDayReturn.size() - 1; } else if (slideHour > yesterdayHour) { index = (slideHour - yesterdayHour); } else if (slideHour < yesterdayHour) { index = (24 - (yesterdayHour - slideHour)) % 24; } statisticsDayReturn.set(index, statisticDayObject.views.intValue()); } catch (Exception e) { return badRequest(e.getMessage()); } } return ok(Json.toJson(statisticsDayReturn)); }
From source file:controllers.Api.Statistic.java
License:Open Source License
public static Result getAccess() { // Variables/*from w ww . j av a 2 s . c o m*/ Integer newValue, accessHour, yesterdayHour, index = 0; DateTime yesterdayDayTime, accessTime; // Yesterday Time Calc yesterdayDayTime = (new DateTime()).withZone(DateTimeZone.forID(session("timezone"))); //yesterdayDayTime = yesterdayDayTime.minusHours(24); yesterdayDayTime = yesterdayDayTime.minusHours(23).minusMinutes(yesterdayDayTime.getMinuteOfHour()) .minusSeconds(yesterdayDayTime.getSecondOfMinute()); yesterdayHour = yesterdayDayTime.getHourOfDay(); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); List<models.Access> accessDay = models.Access.find.where() .ge("timestamp", fmt.print(yesterdayDayTime.toDateTime(DateTimeZone.UTC))).order().asc("timestamp") .findList(); Iterator<models.Access> accessDayIterator = accessDay.iterator(); // 0 Liste initialisieren List<Integer> accessDayReturn = Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // Iterate List while (accessDayIterator.hasNext()) { models.Access access = accessDayIterator.next(); // Access Time Calc accessTime = access.timestamp; accessTime = accessTime.withZone(DateTimeZone.forID(session("timezone"))); accessHour = accessTime.getHourOfDay(); // Set value if (accessHour == yesterdayHour) { index = accessDayReturn.size() - 1; } else if (accessHour > yesterdayHour) { index = accessHour - yesterdayHour; } else if (accessHour < yesterdayHour) { index = (24 - (yesterdayHour - accessHour)) % 24; } newValue = accessDayReturn.get(index) + 1; accessDayReturn.set(index, newValue); } return ok(Json.toJson(accessDayReturn)); }
From source file:de.brazzy.nikki.model.ImageReader.java
License:Open Source License
/** * @return time zone read from EXIF if present, default passed into * constructor otherwise/*w w w.ja v a 2 s. c o m*/ */ public DateTimeZone getTimeZone() { if (nikkiIFD == null) { return this.scanZone; } Entry entry = nikkiIFD.getEntry(ENTRY_TIMEZONE_INDEX, 0); if (entry != null && entry.getValue(0) != null) { String zoneID = (String) entry.getValue(0); return DateTimeZone.forID(zoneID); } else { return this.scanZone; } }
From source file:de.brazzy.nikki.util.TimezoneFinder.java
License:Open Source License
private void parseZones(ObjectInputStream data) throws IOException { for (String zone = data.readUTF(); !zone.equals(""); zone = data.readUTF()) { zones.add(DateTimeZone.forID(zone)); }//w w w . j a va 2s .c om }
From source file:de.brazzy.nikki.view.ScanOptions.java
License:Open Source License
/** * @return time zone selected by the user *//*from www. ja v a 2 s . co m*/ public DateTimeZone getTimezone() { return combobox.getSelectedItem() == null ? null : DateTimeZone.forID((String) combobox.getSelectedItem()); }
From source file:de.javakaffee.kryoserializers.jodatime.JodaDateTimeSerializer.java
License:Apache License
private DateTimeZone readTimeZone(final Input input) { final String tz = input.readString(); return "".equals(tz) ? DateTimeZone.getDefault() : DateTimeZone.forID(tz); }