private static Date parseDatetime(String dateStr) { Date date = null; int len = dateStr.length(); if (len == 10 && dateStr.charAt(4) == '-' && dateStr.charAt(7) == '-') { date = new DateTime(dateStr).toDate(); } else if (len == 8 && dateStr.charAt(2) == ':' && dateStr.charAt(5) == ':') { date = new DateTime("T" + dateStr).toDate(); } else if (len >= 19 && dateStr.charAt(4) == '-' && dateStr.charAt(7) == '-' && dateStr.charAt(13) == ':' && dateStr.charAt(16) == ':') { date = new DateTime(dateStr.replace(" ", "T")).toDate(); } return date; } }
/** * Test when PST-->PDT happens in 2020. -8:00 -> -7:00 See details why confusion happens during * this change: https://en.wikipedia.org/wiki/Pacific_Time_Zone * * This test demonstrates that 2:30 AM will not happen during the daylight saving day on Cron * settings under PDT/PST. Since we let the cron triggered both at March 8th, and 9th, it will * execute at March 9th. */ @Test public void testPSTtoPDTdst2() { final DateTime now = DateTime.now(); final String cronExpression = "0 30 2 8,9 3 ? 2020"; final BasicTimeChecker timeChecker = new BasicTimeChecker("BasicTimeChecker_1", now.getMillis(), DateTimeZone.forID("America/Los_Angeles"), true, true, null, cronExpression); System.out.println("getNextCheckTime = " + timeChecker.getNextCheckTime()); final Condition cond = getCondition(timeChecker); final DateTime aTime = new DateTime(2020, 3, 9, 2, 30, 0, DateTimeZone.forID("America/Los_Angeles")); assertTrue(cond.getNextCheckTime() == aTime.getMillis()); }
@Test public void testGreatest() { assertFunction( "greatest(TIMESTAMP '2002-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 01:04:05.321 +02:09', TIMESTAMP '2000-01-02 01:04:05.321 +02:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2002, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); assertFunction( "greatest(TIMESTAMP '2001-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 04:04:05.321 +10:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY)); }
@Test public void testParseDatetime() { assertFunction("parse_datetime('1960/01/22 03:04', 'YYYY/MM/DD HH:mm')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DATE_TIME_ZONE))); assertFunction("parse_datetime('1960/01/22 03:04 Asia/Oral', 'YYYY/MM/DD HH:mm ZZZZZ')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DateTimeZone.forID("Asia/Oral")))); assertFunction("parse_datetime('1960/01/22 03:04 +0500', 'YYYY/MM/DD HH:mm Z')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DateTimeZone.forOffsetHours(5)))); }
@Test(groups = "fast") public void testLoad() throws CatalogApiException { final DefaultVersionedCatalog c = loader.loadDefaultCatalog(Resources.getResource("versionedCatalog").toString()); Assert.assertEquals(c.getVersions().size(), 4); DateTime dt = new DateTime("2011-01-01T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(0).getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-02-02T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(1).getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-02-03T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(2).getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-03-03T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(3).getEffectiveDate(), dt.toDate()); }
/** * Test when PST-->PDT happens in 2020. -8:00 -> -7:00 See details why confusion happens during * this change: https://en.wikipedia.org/wiki/Pacific_Time_Zone * * This test demonstrates that if the cron is under UTC settings, When daylight saving change * occurs, 2:30 will be changed to 3:30 at that day. */ @Test public void testPSTtoPDTunderUTC() { final DateTime now = DateTime.now(); // 10:30 UTC == 2:30 PST final String cronExpression = "0 30 10 8 3 ? 2020"; final BasicTimeChecker timeChecker = new BasicTimeChecker("BasicTimeChecket_1", now.getMillis(), DateTimeZone.UTC, true, true, null, cronExpression); System.out.println("getNextCheckTime = " + timeChecker.getNextCheckTime()); final Condition cond = getCondition(timeChecker); final DateTime spring2020UTC = new DateTime(2020, 3, 8, 10, 30, 0, DateTimeZone.UTC); final DateTime spring2020PDT = new DateTime(2020, 3, 8, 3, 30, 0, DateTimeZone.forID("America/Los_Angeles")); assertTrue(cond.getNextCheckTime() == spring2020UTC.getMillis()); assertTrue(cond.getNextCheckTime() == spring2020PDT.getMillis()); }
public TimestampStreamReader(StreamDescriptor streamDescriptor, DateTimeZone hiveStorageTimeZone, LocalMemoryContext systemMemoryContext) { this.streamDescriptor = requireNonNull(streamDescriptor, "stream is null"); this.baseTimestampInSeconds = new DateTime(2015, 1, 1, 0, 0, requireNonNull(hiveStorageTimeZone, "hiveStorageTimeZone is null")).getMillis() / MILLIS_PER_SECOND; this.systemMemoryContext = requireNonNull(systemMemoryContext, "systemMemoryContext is null"); }
@Test public void testDatePlusInterval() { assertFunction("DATE '2001-1-22' + INTERVAL '3' day", DATE, toDate(new DateTime(2001, 1, 25, 0, 0, 0, 0, UTC))); assertFunction("INTERVAL '3' day + DATE '2001-1-22'", DATE, toDate(new DateTime(2001, 1, 25, 0, 0, 0, 0, UTC))); assertFunction("DATE '2001-1-22' + INTERVAL '3' month", DATE, toDate(new DateTime(2001, 4, 22, 0, 0, 0, 0, UTC))); assertFunction("INTERVAL '3' month + DATE '2001-1-22'", DATE, toDate(new DateTime(2001, 4, 22, 0, 0, 0, 0, UTC))); assertFunction("DATE '2001-1-22' + INTERVAL '3' year", DATE, toDate(new DateTime(2004, 1, 22, 0, 0, 0, 0, UTC))); assertFunction("INTERVAL '3' year + DATE '2001-1-22'", DATE, toDate(new DateTime(2004, 1, 22, 0, 0, 0, 0, UTC))); assertInvalidFunction("DATE '2001-1-22' + INTERVAL '3' hour", "Cannot add hour, minutes or seconds to a date"); assertInvalidFunction("INTERVAL '3' hour + DATE '2001-1-22'", "Cannot add hour, minutes or seconds to a date"); }
@Test(groups = "fast") public void testLoadCatalogFromInsideResourceFolder() throws CatalogApiException { final DefaultVersionedCatalog c = loader.loadDefaultCatalog("com/acme/SpyCarCustom.xml"); Assert.assertEquals(c.getVersions().size(), 1); final DateTime dt = new DateTime("2015-10-04T00:00:00+00:00"); Assert.assertEquals(c.getEffectiveDate(), dt.toDate()); Assert.assertEquals(c.getCatalogName(), "SpyCarCustom"); }
/** * Test when PDT-->PST happens in 2020. -7:00 -> -8:00 See details why confusion happens during * this change: https://en.wikipedia.org/wiki/Pacific_Time_Zone * * This test cronDayLightPacificWinter2 is in order to be compared against the * cronDayLightPacificWinter1. * * In this Test, we let job run at 0:59 at Nov.1st, 2020. it shows that it is 7:59 UTC The test * shows 7:59 UTC jump to 9:00 UTC. */ @Test public void testPDTtoPSTdst2() { final DateTime now = DateTime.now(); // 7:59 UTC == 0:59 PDT (difference is 7 hours) final String cronExpression = "0 59 0 1,2 11 ? 2020"; final BasicTimeChecker timeChecker = new BasicTimeChecker("BasicTimeChecket_1", now.getMillis(), DateTimeZone.forID("America/Los_Angeles"), true, true, null, cronExpression); System.out.println("getNextCheckTime = " + timeChecker.getNextCheckTime()); final Condition cond = getCondition(timeChecker); // 7:59 UTC == 0:59 PDT (difference is 7 hours) final DateTime winter2020 = new DateTime(2020, 11, 1, 7, 59, 0, DateTimeZone.UTC); final DateTime winter2020_2 = new DateTime(2020, 11, 1, 0, 59, 0, DateTimeZone.forID("America/Los_Angeles")); // Local time remains the same. assertTrue(cond.getNextCheckTime() == winter2020.getMillis()); assertTrue(cond.getNextCheckTime() == winter2020_2.getMillis()); }
public V3X509CertificateGenerator(Date startDate, X500Name issuerDn, X500Name subjectDn, PublicKey publicKey, BigInteger serialNumber) { SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded()); this.v3CertGen = new X509v3CertificateBuilder(issuerDn, serialNumber, startDate, new DateTime().plusYears(YEARS).toDate(), subjectDn, publicKeyInfo); }