public DateTimeZone getTimeZone() { return localNow.getZone(); }
public static long packDateTimeWithZone(DateTime dateTime) { return DateTimeEncoding.packDateTimeWithZone(dateTime.getMillis(), dateTime.getZone().getID()); }
public static void testDate() { DateTimeFormatter df = DateTimeFormat.forPattern("dd MM yyyy HH:mm:ss.SSS Z"); DateTime temp = df.withOffsetParsed().parseDateTime("30 11 2012 12:08:56.235 +0700"); DateTimeZone theZone = temp.getZone(); Date date = temp.toDate(); DateTime dateTime = new DateTime(date); DateTimeFormatter df2 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSZZ"); DateTimeFormatter df3 = df2.withZone(theZone); System.out.println(dateTime.toString(df2)); System.out.println(dateTime.toString(df3)); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Result result = (Result) o; if (timestamp != null ? !(timestamp.isEqual(result.timestamp) && timestamp.getZone().getOffset(timestamp) == result.timestamp.getZone().getOffset(result.timestamp)) : result.timestamp != null) { return false; } if (value != null ? !value.equals(result.value) : result.value != null) { return false; } return true; }
/** * Get this object as a DateTime, returning <code>this</code> if possible. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); if (getZone() == zone) { return this; } return super.toDateTime(zone); }
/** * Returns a copy of this ZonedDateTime changing the zone offset to the earlier * of the two valid offsets at a local time-line overlap. * <p> * This method only has any effect when the local time-line overlaps, such as at * an autumn daylight savings cutover. In this scenario, there are two valid offsets * for the local date-time. Calling this method will return a date-time with the * earlier of the two selected. * <p> * If this method is called when it is not an overlap, this is returned. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the earliest valid offset for the local datetime */ public DateTime withEarlierOffsetAtOverlap() { long newMillis = getZone().adjustOffset(getMillis(), false); return withMillis(newMillis); }
/** * Returns a copy of this ZonedDateTime changing the zone offset to the later * of the two valid offsets at a local time-line overlap. * <p> * This method only has any effect when the local time-line overlaps, such as at * an autumn daylight savings cutover. In this scenario, there are two valid offsets * for the local date-time. Calling this method will return a date-time with the * later of the two selected. * <p> * If this method is called when it is not an overlap, this is returned. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the latest valid offset for the local datetime */ public DateTime withLaterOffsetAtOverlap() { long newMillis = getZone().adjustOffset(getMillis(), true); return withMillis(newMillis); }
/** * Get this object as a DateTime, returning <code>this</code> if possible. * * @param zone time zone to apply, or default if null * @return a DateTime using the same millis */ public DateTime toDateTime(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); if (getZone() == zone) { return this; } return super.toDateTime(zone); }
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
/** * Returns a copy of this ZonedDateTime changing the zone offset to the earlier * of the two valid offsets at a local time-line overlap. * <p> * This method only has any effect when the local time-line overlaps, such as at * an autumn daylight savings cutover. In this scenario, there are two valid offsets * for the local date-time. Calling this method will return a date-time with the * earlier of the two selected. * <p> * If this method is called when it is not an overlap, this is returned. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the earliest valid offset for the local datetime */ public DateTime withEarlierOffsetAtOverlap() { long newMillis = getZone().adjustOffset(getMillis(), false); return withMillis(newMillis); }
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
/** * Returns a copy of this ZonedDateTime changing the zone offset to the later * of the two valid offsets at a local time-line overlap. * <p> * This method only has any effect when the local time-line overlaps, such as at * an autumn daylight savings cutover. In this scenario, there are two valid offsets * for the local date-time. Calling this method will return a date-time with the * later of the two selected. * <p> * If this method is called when it is not an overlap, this is returned. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the latest valid offset for the local datetime */ public DateTime withLaterOffsetAtOverlap() { long newMillis = getZone().adjustOffset(getMillis(), true); return withMillis(newMillis); }
private static SqlTimestampWithTimeZone toTimestampWithTimeZone(DateTime dateTime) { return new SqlTimestampWithTimeZone(dateTime.getMillis(), dateTime.getZone().toTimeZone()); } }
/** * Returns a copy of this datetime with a different time zone, preserving the * field values. * <p> * This method is useful for finding the millisecond time in another timezone. * For example, if this instant holds 12:30 in Europe/London (ie. 12:30Z), * the result from this method with Europe/Paris would be 12:30 (ie. 11:30Z). * <p> * The returned object will be a new instance of the same implementation type. * This method changes the time zone and the millisecond instant to keep * the field values the same. * The returned object will be either be a new instance or <code>this</code>. * * @param newZone the new time zone, null means default * @return a copy of this datetime with a different time zone * @see #withZone */ public DateTime withZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return this; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); return new DateTime(millis, getChronology().withZone(newZone)); }
/** * Returns a copy of this datetime with a different time zone, preserving the * field values. * <p> * This method is useful for finding the millisecond time in another timezone. * For example, if this instant holds 12:30 in Europe/London (ie. 12:30Z), * the result from this method with Europe/Paris would be 12:30 (ie. 11:30Z). * <p> * The returned object will be a new instance of the same implementation type. * This method changes the time zone and the millisecond instant to keep * the field values the same. * The returned object will be either be a new instance or <code>this</code>. * * @param newZone the new time zone, null means default * @return a copy of this datetime with a different time zone * @see #withZone */ public DateTime withZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return this; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); return new DateTime(millis, getChronology().withZone(newZone)); }
/** * Test Base Cron Functionality. */ @Test public void testQuartzCurrentZone() { final DateTime now = DateTime.now(); final String cronExpression = "0 0 0 31 12 ? 2050"; final BasicTimeChecker timeChecker = new BasicTimeChecker("BasicTimeChecket_1", now.getMillis(), now.getZone(), true, true, null, cronExpression); System.out.println("getNextCheckTime = " + timeChecker.getNextCheckTime()); final Condition cond = getCondition(timeChecker); // 2556086400000L represent for "2050-12-31T00:00:00.000-08:00" final DateTime year2050 = new DateTime(2050, 12, 31, 0, 0, 0, now.getZone()); assertTrue(cond.getNextCheckTime() == year2050.getMillis()); }
@Test public void testVersionParser() throws Exception { Properties props = new Properties(); props.put(DateTimeDatasetVersionFinder.RETENTION_DATE_TIME_PATTERN_KEY, "yyyy/MM/dd/hh/mm"); DateTimeDatasetVersionFinder parser = new DateTimeDatasetVersionFinder(this.fs, props); Assert.assertEquals(parser.versionClass(), TimestampedDatasetVersion.class); Assert.assertEquals(parser.globVersionPattern(), new Path("*/*/*/*/*")); DateTime version = parser.getDatasetVersion(new Path("2015/06/01/10/12"), this.fs.getFileStatus(testDataPathDummyPath)).getDateTime(); Assert.assertEquals(version.getZone(), DateTimeZone.forID(ConfigurationKeys.PST_TIMEZONE_NAME)); Assert.assertEquals(version, new DateTime(2015, 6, 1, 10, 12, 0, 0, DateTimeZone.forID(ConfigurationKeys.PST_TIMEZONE_NAME))); Assert.assertEquals( PathUtils.getPathWithoutSchemeAndAuthority(parser .getDatasetVersion(new Path("2015/06/01/10/12"), this.fs.getFileStatus(testDataPathDummyPath)) .getPathsToDelete().iterator().next()), PathUtils.getPathWithoutSchemeAndAuthority(this.testDataPathDummyPath)); }
@Test public void testVersionParserWithTimeZone() throws Exception { Properties props = new Properties(); props.put(DateTimeDatasetVersionFinder.RETENTION_DATE_TIME_PATTERN_KEY, "yyyy/MM/dd/hh/mm"); props.put(DateTimeDatasetVersionFinder.RETENTION_DATE_TIME_PATTERN_TIMEZONE_KEY, "UTC"); DateTimeDatasetVersionFinder parser = new DateTimeDatasetVersionFinder(this.fs, props); Assert.assertEquals(parser.versionClass(), TimestampedDatasetVersion.class); Assert.assertEquals(parser.globVersionPattern(), new Path("*/*/*/*/*")); DateTime version = parser.getDatasetVersion(new Path("2015/06/01/10/12"), this.fs.getFileStatus(testDataPathDummyPath)).getDateTime(); Assert.assertEquals(version.getZone(), DateTimeZone.forID("UTC")); Assert.assertEquals(version, new DateTime(2015, 6, 1, 10, 12, 0, 0, DateTimeZone.forID("UTC"))); Assert.assertEquals( PathUtils.getPathWithoutSchemeAndAuthority(parser .getDatasetVersion(new Path("2015/06/01/10/12"), this.fs.getFileStatus(testDataPathDummyPath)) .getPathsToDelete().iterator().next()), PathUtils.getPathWithoutSchemeAndAuthority(this.testDataPathDummyPath)); }
@Test(groups = "slow", enabled = false) public void testWithGMTPlus8() throws SQLException { final LocalDate date1_1 = new LocalDate(2014, 10, 1, GregorianChronology.getInstance(DATE_TZ_PLUS_8_GMT)); // We chose a time such that it moves to next day final DateTime date2_1 = new DateTime(2014, 10, 1, 22, 48, 56, DATE_TZ_PLUS_8_GMT); insertData(date1_1, date2_1, date2_1); final FullOfDates result = readData(); assertEquals(result.getDate1().compareTo(date1_1), 0); assertEquals(result.getDate2().compareTo(date2_1), 0); assertEquals(result.getDate2().getZone().toString(), "UTC"); }
@Test(groups = "slow", enabled = false) public void testWithGMTMinus20() throws SQLException { final LocalDate date1_1 = new LocalDate(2014, 10, 1, GregorianChronology.getInstance(DATE_TZ_MINUS_20_GMT)); // We chose a time such that it moves to next day final DateTime date2_1 = new DateTime(2014, 10, 1, 16, 48, 56, DATE_TZ_MINUS_20_GMT); insertData(date1_1, date2_1, date2_1); final FullOfDates result = readData(); assertEquals(result.getDate1().compareTo(date1_1), 0); assertEquals(result.getDate2().compareTo(date2_1), 0); assertEquals(result.getDate2().getZone().toString(), "UTC"); }