List of usage examples for java.util Calendar toInstant
public final Instant toInstant()
From source file:ru.anr.base.BaseParent.java
/** * Transforms the given calendar value to a zoned date from the default * (UTC) time zone./*from w w w .ja va 2 s . c om*/ * * @param calendar * Some calendar value * @return A zoned date-time */ public static ZonedDateTime date(Calendar calendar) { return ZonedDateTime.ofInstant(calendar.toInstant(), DEFAULT_TIMEZONE); }
From source file:com.orange.cepheus.broker.SubscriptionsTest.java
@Test public void addSubscriptionWithZeroDurationTest() throws SubscriptionException, URISyntaxException, SubscriptionPersistenceException { SubscribeContext subscribeContext = createSubscribeContextTemperature(); subscribeContext.setDuration("PT0S"); String subscriptionId = subscriptions.addSubscription(subscribeContext); Assert.notNull(subscriptionId);/* w w w .j av a 2 s.co m*/ Assert.hasLength(subscriptionId); Subscription subscription = subscriptions.getSubscription(subscriptionId); Assert.notNull(subscription); Assert.notNull(subscription.getExpirationDate()); Assert.notNull(subscription.getSubscriptionId()); assertEquals(subscriptionId, subscription.getSubscriptionId()); Calendar c = (Calendar) Calendar.getInstance().clone(); c.add(Calendar.MONTH, 1); c.add(Calendar.HOUR, 24); assertFalse(subscription.getExpirationDate().isAfter(c.toInstant())); c.add(Calendar.HOUR, -48); assertFalse(subscription.getExpirationDate().isBefore(c.toInstant())); Assert.isTrue(subscriptionsRepository.getAllSubscriptions().size() == 1); }
From source file:com.orange.cepheus.broker.LocalRegistrationsTest.java
@Test public void test1MonthDuration() throws Exception { RegisterContext registerContext = createRegistrationContext(); registerContext.setDuration("P1M"); localRegistrations.updateRegistrationContext(registerContext); Calendar c = (Calendar) Calendar.getInstance().clone(); c.add(Calendar.MONTH, 1);/*from w w w . j a va2s . c om*/ c.add(Calendar.HOUR, 24); Registration registration = localRegistrations.getRegistration(registerContext.getRegistrationId()); assertFalse(registration.getExpirationDate().isAfter(c.toInstant())); c.add(Calendar.HOUR, -48); assertFalse(registration.getExpirationDate().isBefore(c.toInstant())); }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression from the provided {@link Calendar} instance * * @param calendar the {@link Calendar} instance * @return the CRON expression//from w ww . j ava2s . com * @throws NullPointerException * if {@code calendar} is null */ public static String createCronFromCalendar(Calendar calendar) { requireNonNull(calendar, "Calendar instance cannot be null"); LocalDateTime temporal = LocalDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault()); return createCronFromTemporal(temporal); }
From source file:org.hippoecm.frontend.plugins.standards.datetime.DateTimePrinter.java
static DateTimePrinter of(final Calendar calendar) { return calendar != null ? of(calendar.toInstant()) : EmptyDateTimePrinter.INSTANCE; }
From source file:org.nuxeo.ecm.platform.rendition.service.TestRenditionService.java
@Test public void shouldPreventAdminFromReusingOthersNonVersionedStoredRendition() throws Exception { DocumentModel folder = createFolderWithChildren(); String renditionName = ZIP_TREE_EXPORT_RENDITION_DEFINITION; Rendition totoRendition;/* w w w.ja v a2 s.c o m*/ // get rendition as non-admin user 'toto' NuxeoPrincipal totoPrincipal = Framework.getService(UserManager.class).getPrincipal("toto"); try (CoreSession userSession = coreFeature.openCoreSession(totoPrincipal)) { folder = userSession.getDocument(folder.getRef()); totoRendition = renditionService.getRendition(folder, renditionName, true); assertTrue(totoRendition.isStored()); } nextTransaction(); eventService.waitForAsyncCompletion(); coreFeature.getStorageConfiguration().maybeSleepToNextSecond(); // now get rendition as admin user 'Administrator' folder = session.getDocument(folder.getRef()); Rendition rendition = renditionService.getRendition(folder, renditionName, true); assertTrue(rendition.isStored()); assertTrue(rendition.isCompleted()); // verify Administrator's rendition is different from user's rendition, is larger than user's rendition, // and was created later assertNotEquals(rendition.getHostDocument().getRef(), totoRendition.getHostDocument().getRef()); long adminZipEntryCount = countZipEntries(new ZipInputStream(rendition.getBlob().getStream())); long totoZipEntryCount = countZipEntries(new ZipInputStream(totoRendition.getBlob().getStream())); assertTrue( String.format("Admin rendition entry count %s should be greater than user rendition entry count %s", adminZipEntryCount, totoZipEntryCount), adminZipEntryCount > totoZipEntryCount); Calendar adminModificationDate = rendition.getModificationDate(); Calendar totoModificationDate = totoRendition.getModificationDate(); assertTrue( String.format("Admin rendition modif date %s should be after user rendition modif date %s", adminModificationDate.toInstant(), totoModificationDate.toInstant()), adminModificationDate.after(totoModificationDate)); }