List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.google.gerrit.server.config.ScheduleConfig.java
License:Apache License
private static long initialDelay(Config rc, String section, String subsection, String keyStartTime, DateTime now, long interval) { long delay = MISSING_CONFIG; String start = rc.getString(section, subsection, keyStartTime); try {//from ww w.j a v a 2s .co m if (start != null) { DateTimeFormatter formatter; MutableDateTime startTime = now.toMutableDateTime(); try { formatter = ISODateTimeFormat.hourMinute(); LocalTime firstStartTime = formatter.parseLocalTime(start); startTime.hourOfDay().set(firstStartTime.getHourOfDay()); startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour()); } catch (IllegalArgumentException e1) { formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US); LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start); startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek()); startTime.hourOfDay().set(firstStartDateTime.getHourOfDay()); startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour()); } startTime.secondOfMinute().set(0); startTime.millisOfSecond().set(0); long s = startTime.getMillis(); long n = now.getMillis(); delay = (s - n) % interval; if (delay <= 0) { delay += interval; } } else { log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section, keyStartTime)); } } catch (IllegalArgumentException e2) { log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime), e2); delay = INVALID_CONFIG; } return delay; }
From source file:com.google.ical.compat.jodatime.TimeZoneConverter.java
License:Apache License
/** * return a <code>java.util.Timezone</code> object that delegates to * the given Joda <code>DateTimeZone</code>. *//*from w ww . j av a 2 s . c o m*/ public static TimeZone toTimeZone(final DateTimeZone dtz) { TimeZone tz = new TimeZone() { @Override public void setRawOffset(int n) { throw new UnsupportedOperationException(); } @Override public boolean useDaylightTime() { long firstTransition = MILLIS_SINCE_1_JAN_2000_UTC; return firstTransition != dtz.nextTransition(firstTransition); } @Override public boolean inDaylightTime(Date d) { long t = d.getTime(); return dtz.getStandardOffset(t) != dtz.getOffset(t); } @Override public int getRawOffset() { return dtz.getStandardOffset(0); } @Override public int getOffset(long instant) { // This method is not abstract, but it normally calls through to the // method below. // It's optimized here since there's a direct equivalent in // DateTimeZone. // DateTimeZone and java.util.TimeZone use the same // epoch so there's no translation of instant required. return dtz.getOffset(instant); } @Override public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) { int millis = milliseconds; // milliseconds is day in standard time int hour = millis / MILLISECONDS_PER_HOUR; millis %= MILLISECONDS_PER_HOUR; int minute = millis / MILLISECONDS_PER_MINUTE; millis %= MILLISECONDS_PER_MINUTE; int second = millis / MILLISECONDS_PER_SECOND; millis %= MILLISECONDS_PER_SECOND; if (era == GregorianCalendar.BC) { year = -(year - 1); } // get the time in UTC in case a timezone has changed it's standard // offset, e.g. rid of a half hour from UTC. DateTime dt = null; try { dt = new DateTime(year, month + 1, day, hour, minute, second, millis, dtz); } catch (IllegalArgumentException ex) { // Java does not complain if you try to convert a Date that does not // exist due to the offset shifting forward, but Joda time does. // Since we're trying to preserve the semantics of TimeZone, shift // forward over the gap so that we're on a time that exists. // This assumes that the DST correction is one hour long or less. if (hour < 23) { dt = new DateTime(year, month + 1, day, hour + 1, minute, second, millis, dtz); } else { // Some timezones shift at midnight. Calendar c = new GregorianCalendar(); c.clear(); c.setTimeZone(TimeZone.getTimeZone("UTC")); c.set(year, month, day, hour, minute, second); c.add(Calendar.HOUR_OF_DAY, 1); int year2 = c.get(Calendar.YEAR), month2 = c.get(Calendar.MONTH), day2 = c.get(Calendar.DAY_OF_MONTH), hour2 = c.get(Calendar.HOUR_OF_DAY); dt = new DateTime(year2, month2 + 1, day2, hour2, minute, second, millis, dtz); } } // since millis is in standard time, we construct the equivalent // GMT+xyz timezone and use that to convert. int offset = dtz.getStandardOffset(dt.getMillis()); DateTime stdDt = new DateTime(year, month + 1, day, hour, minute, second, millis, DateTimeZone.forOffsetMillis(offset)); return getOffset(stdDt.getMillis()); } @Override public String toString() { return dtz.toString(); } @Override public boolean equals(Object that) { if (!(that instanceof TimeZone)) { return false; } TimeZone thatTz = (TimeZone) that; return getID().equals(thatTz.getID()) && hasSameRules(thatTz); } @Override public int hashCode() { return getID().hashCode(); } private static final long serialVersionUID = 58752546800455L; }; // Now fix the tzids. DateTimeZone has a bad habit of returning // "+06:00" when it should be "GMT+06:00" String newTzid = cleanUpTzid(dtz.getID()); tz.setID(newTzid); return tz; }
From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java
License:Apache License
/** * Constructor for GpsTime. Input values are all in GPS time. * @param year Year/*from ww w. j a v a 2s .com*/ * @param month Month from 1 to 12 * @param day Day from 1 to 31 * @param hour Hour from 0 to 23 * @param minute Minute from 0 to 59 * @param second Second from 0 to 59 */ public GpsTime(int year, int month, int day, int hour, int minute, double second) { DateTime utcDateTime = new DateTime(year, month, day, hour, minute, (int) second, (int) (second * 1000) % 1000, UTC_ZONE); // Since input time is already specify in GPS time, no need to count leap second here. gpsNanos = TimeUnit.MILLISECONDS.toNanos(utcDateTime.getMillis()) - GPS_UTC_EPOCH_OFFSET_NANOS; }
From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java
License:Apache License
/** * Constructor/*from ww w .ja v a 2s . c o m*/ * @param dateTime is created using GPS time values. */ public GpsTime(DateTime dateTime) { gpsNanos = TimeUnit.MILLISECONDS.toNanos(dateTime.getMillis()) - GPS_UTC_EPOCH_OFFSET_NANOS; }
From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java
License:Apache License
/** * Creates a GPS time using a UTC based date and time. * @param dateTime represents the current time in UTC time, must be after 2009 *//*from w ww. ja v a 2 s .co m*/ public static GpsTime fromUtc(DateTime dateTime) { return new GpsTime(TimeUnit.MILLISECONDS.toNanos(dateTime.getMillis()) + TimeUnit.SECONDS.toNanos(GpsTime.getLeapSecond(dateTime) - GPS_UTC_EPOCH_OFFSET_SECONDS)); }
From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java
License:Apache License
/** * @return Day of year in GPS time (GMT time) *//*from w w w . jav a 2 s .c o m*/ public static int getCurrentDayOfYear() { DateTime current = DateTime.now(DateTimeZone.UTC); // Since current is derived from UTC time, we need to add leap second here. long gpsTimeMillis = current.getMillis() + getLeapSecond(current); DateTime gpsCurrent = new DateTime(gpsTimeMillis, UTC_ZONE); return gpsCurrent.getDayOfYear(); }
From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java
License:Apache License
/** * @return a DateTime with leap seconds considered. */// w ww .j ava 2 s . co m public DateTime getUtcDateTime() { DateTime gpsDateTime = getGpsDateTime(); return new DateTime(gpsDateTime.getMillis() - TimeUnit.SECONDS.toMillis(getLeapSecond(gpsDateTime)), UTC_ZONE); }
From source file:com.google.samples.apps.abelana.AbelanaThings.java
License:Open Source License
public static String getImage(String name) { final String Bucket = "abelana"; DateTime soon = DateTime.now(DateTimeZone.UTC).plusMinutes(20); long expires = soon.getMillis() / 1000; String stringToSign = "GET\n\n\n" + expires + "\n" + "/" + Bucket + "/" + name + ".webp"; String uri = "https://storage.googleapis.com/abelana/" + name + ".webp" + "?GoogleAccessId=" + credential.getServiceAccountId() + "&Expires=" + expires + "&Signature=" + Uri.encode(signData(stringToSign)); return uri;// www. j av a 2 s . c om }
From source file:com.google.samples.apps.iosched.explore.ExploreSessionsFragment.java
License:Open Source License
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { DateTimeFormatter formatter = DateTimeFormat.forPattern("E dd.MMMM yyyy"); DateTime dateToUse = null;//www . j a va2 s . co m DateTime startDate = null; DateTime endDate = null; if (mSessionDate != null) { dateToUse = formatter.parseDateTime(mSessionDate); startDate = dateToUse.plusHours(0); endDate = dateToUse.plusHours(23); } switch (id) { case ExploreSessionsQuery.NORMAL_TOKEN: return new CursorLoader(getActivity(), mCurrentUri, ExploreSessionsQuery.NORMAL_PROJECTION, mSessionDate != null ? ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION : null, mSessionDate != null ? new String[] { startDate.getMillis() + "", endDate.getMillis() + "" } : null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); case ExploreSessionsQuery.SEARCH_TOKEN: return new CursorLoader(getActivity(), mCurrentUri, ExploreSessionsQuery.SEARCH_PROJECTION, mSessionDate != null ? ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION : null, mSessionDate != null ? new String[] { startDate.getMillis() + "", endDate.getMillis() + "" } : null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); case TAG_METADATA_TOKEN: return TagMetadata.createCursorLoader(getActivity()); default: return null; } }
From source file:com.google.soxlib.Utility.java
License:Apache License
/** * Convert from a SOX string timestamp into a "unix timestamp" (milliseconds * since 1970)./*w w w .j a v a 2 s . co m*/ * * @param timestamp as a SOX string (i.e. from a timestamp field). * @return milliseconds since Jan 1, 1970 UTC. */ public static final long getUnixTimeFromTimestamp(String timestamp) { DateTime dt = new DateTime(timestamp); return dt.getMillis(); }