Java Code Examples for java.time.OffsetDateTime#now()
The following examples show how to use
java.time.OffsetDateTime#now() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKOffsetDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test public void now_Clock_allSecsInDay_offset() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2); assertEquals(test.getHour(), (i / (60 * 60)) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); assertEquals(test.getOffset(), OFFSET_PONE); } }
Example 2
Source File: PageSavedComponentService.java From jweb-cms with GNU Affero General Public License v3.0 | 6 votes |
@Transactional public PageSavedComponent update(String id, UpdateSavedComponentRequest request) { PageSavedComponent pageComponent = get(id); pageComponent.name = request.name; pageComponent.displayName = request.displayName; pageComponent.status = SavedComponentStatus.ACTIVE; pageComponent.attributes = request.attributes == null ? null : JSON.toJSON(request.attributes); pageComponent.updatedBy = request.requestBy; pageComponent.updatedTime = OffsetDateTime.now(); repository.update(pageComponent.id, pageComponent); SavedComponentChangedMessage message = new SavedComponentChangedMessage(); message.id = pageComponent.id; message.name = pageComponent.name; message.componentName = pageComponent.componentName; message.displayName = pageComponent.displayName; message.attributes = request.attributes; message.status = pageComponent.status; message.createdBy = pageComponent.createdBy; message.createdTime = pageComponent.createdTime; message.updatedBy = pageComponent.updatedBy; message.updatedTime = pageComponent.updatedTime; publisher.publish(message); return pageComponent; }
Example 3
Source File: TCKOffsetDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test public void now_Clock_allSecsInDay_offset() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2); assertEquals(test.getHour(), (i / (60 * 60)) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); assertEquals(test.getOffset(), OFFSET_PONE); } }
Example 4
Source File: ITOrganizationsApi.java From influxdb-client-java with MIT License | 6 votes |
@Test void createOrganization() { OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC); String orgName = generateName("Constant Pro"); Organization organization = organizationsApi.createOrganization(orgName); LOG.log(Level.INFO, "Created organization: {0}", organization); Assertions.assertThat(organization).isNotNull(); Assertions.assertThat(organization.getId()).isNotBlank(); Assertions.assertThat(organization.getName()).isEqualTo(orgName); Assertions.assertThat(organization.getLinks()).isNotNull(); Assertions.assertThat(organization.getCreatedAt()).isAfter(now); Assertions.assertThat(organization.getUpdatedAt()).isAfter(now); Assertions.assertThat(organization.getLinks().getBuckets()).isEqualTo("/api/v2/buckets?org=" + orgName); Assertions.assertThat(organization.getLinks().getDashboards()).isEqualTo("/api/v2/dashboards?org=" + orgName); Assertions.assertThat(organization.getLinks().getMembers()).isEqualTo("/api/v2/orgs/" + organization.getId() + "/members"); Assertions.assertThat(organization.getLinks().getOwners()).isEqualTo("/api/v2/orgs/" + organization.getId() + "/owners"); Assertions.assertThat(organization.getLinks().getSelf()).isEqualTo("/api/v2/orgs/" + organization.getId()); Assertions.assertThat(organization.getLinks().getTasks()).isEqualTo("/api/v2/tasks?org=" + orgName); Assertions.assertThat(organization.getLinks().getLabels()).isEqualTo("/api/v2/orgs/" + organization.getId() + "/labels"); Assertions.assertThat(organization.getLinks().getSecrets()).isEqualTo("/api/v2/orgs/" + organization.getId() + "/secrets"); }
Example 5
Source File: AbstractRecordService.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public T create(User user, RecordOperationConfig config, RepositoryConnection conn) { validateCreationConfig(config); CreateActivity createActivity = provUtils.startCreateActivity(user); try { OffsetDateTime now = OffsetDateTime.now(); T record = createRecord(user, config, now, now, conn); provUtils.endCreateActivity(createActivity, record.getResource()); return record; } catch (Exception e) { provUtils.removeActivity(createActivity); throw e; } }
Example 6
Source File: TCKOffsetDateTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void now_Clock_allSecsInDay_beforeEpoch() { LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L); for (int i =-1; i >= -(24 * 60 * 60); i--) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getYear(), 1969); assertEquals(test.getMonth(), Month.DECEMBER); assertEquals(test.getDayOfMonth(), 31); expected = expected.minusSeconds(1); assertEquals(test.toLocalTime(), expected); assertEquals(test.getOffset(), ZoneOffset.UTC); } }
Example 7
Source File: TCKOffsetDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void now_Clock_offsets() { OffsetDateTime base = OffsetDateTime.of(1970, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC); for (int i = -9; i < 15; i++) { ZoneOffset offset = ZoneOffset.ofHours(i); Clock clock = Clock.fixed(base.toInstant(), offset); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getHour(), (12 + i) % 24); assertEquals(test.getMinute(), 0); assertEquals(test.getSecond(), 0); assertEquals(test.getNano(), 0); assertEquals(test.getOffset(), offset); } }
Example 8
Source File: ReplicasHelperTest.java From pg-index-health with Apache License 2.0 | 5 votes |
@Test void getLastStatsResetDateLogMessageWithResetTimestamp() { final PgHost host = PgHostImpl.ofPrimary(); final OffsetDateTime resetDate = OffsetDateTime.now(); final StatisticsMaintenanceOnHost statisticsMaintenance = Mockito.mock(StatisticsMaintenanceOnHost.class); Mockito.when(statisticsMaintenance.getLastStatsResetTimestamp()).thenReturn(Optional.of(resetDate.minusDays(123L))); final String logMessage = ReplicasHelper.getLastStatsResetDateLogMessage(host, Collections.singletonMap(host, statisticsMaintenance)); assertThat(logMessage, startsWith("Last statistics reset on this host was 123 days ago (")); }
Example 9
Source File: TCKOffsetDateTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void now() { OffsetDateTime expected = OffsetDateTime.now(Clock.systemDefaultZone()); OffsetDateTime test = OffsetDateTime.now(); long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); if (diff >= 100000000) { // may be date change expected = OffsetDateTime.now(Clock.systemDefaultZone()); test = OffsetDateTime.now(); diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); } assertTrue(diff < 100000000); // less than 0.1 secs }
Example 10
Source File: UserAutoLoginTokenWebServiceImplTest.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
@Test public void create() { CreateUserAutoLoginTokenRequest request = new CreateUserAutoLoginTokenRequest(); request.userId = UUID.randomUUID().toString(); request.expireTime = OffsetDateTime.now(); request.requestBy = "test"; ContainerResponse response = app.post("/api/user/token").setEntity(request).execute(); UserAutoLoginTokenResponse token = (UserAutoLoginTokenResponse) response.getEntity(); assertNotNull(token.token); }
Example 11
Source File: OAuthTest.java From robozonky with Apache License 2.0 | 5 votes |
@Test void refresh() { final String originalTokenId = UUID.randomUUID() .toString(); final ZonkyApiToken originToken = new ZonkyApiTokenImpl(UUID.randomUUID() .toString(), originalTokenId, OffsetDateTime.now()); final ZonkyApiTokenImpl resultToken = mock(ZonkyApiTokenImpl.class); final ZonkyOAuthApi api = mock(ZonkyOAuthApi.class); when(api.refresh(eq(originalTokenId), anyString())).thenReturn(resultToken); final Api<ZonkyOAuthApi> wrapper = new Api<>(api); final OAuth oauth = new OAuth(wrapper); final ZonkyApiToken returnedToken = oauth.refresh(originToken); assertThat(returnedToken).isEqualTo(resultToken); }
Example 12
Source File: PageCommentService.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
@Transactional public PageComment update(String id, UpdateCommentRequest request) { PageComment comment = get(id); if (request.content != null) { comment.content = request.content; } if (request.status != null) { comment.status = request.status; } comment.updatedBy = request.requestBy; comment.updatedTime = OffsetDateTime.now(); return repository.update(id, comment); }
Example 13
Source File: OffsetDateTimeSerTest.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Test public void testSerializationAsTimestamp03Milliseconds() throws Exception { OffsetDateTime date = OffsetDateTime.now(Z3); String value = MAPPER.writer() .with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .without(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS) .writeValueAsString(date); assertEquals("The value is not correct.", Long.toString(date.toInstant().toEpochMilli()), value); }
Example 14
Source File: SecureDataServiceTest.java From cerberus with Apache License 2.0 | 5 votes |
@Test public void test_that_reencrypt_version_file_calls_reencrypt_bytes() { String newCiphertext = "fasdfkxcvasdff as"; byte[] newCiphertextBytes = newCiphertext.getBytes(StandardCharsets.UTF_8); String pathToFile = "app/sdb/object"; String versionId = "version"; OffsetDateTime now = OffsetDateTime.now(ZoneId.of("UTC")); when(dateTimeSupplier.get()).thenReturn(now); SecureDataVersionRecord record = new SecureDataVersionRecord() .setType(SecureDataType.FILE) .setPath(pathToFile) .setEncryptedBlob(ciphertextBytes) .setSizeInBytes(ciphertextBytes.length); when(encryptionService.reencrypt(ciphertextBytes, pathToFile)).thenReturn(newCiphertextBytes); when(secureDataVersionDao.readSecureDataVersionByIdLocking(versionId)) .thenReturn(Optional.of(record)); secureDataService.reencryptDataVersion(versionId); verify(secureDataVersionDao).readSecureDataVersionByIdLocking(versionId); ArgumentCaptor<SecureDataVersionRecord> argument = ArgumentCaptor.forClass(SecureDataVersionRecord.class); verify(secureDataVersionDao).updateSecureDataVersion(argument.capture()); assertEquals(now, argument.getValue().getLastRotatedTs()); assertArrayEquals(newCiphertextBytes, argument.getValue().getEncryptedBlob()); }
Example 15
Source File: TCKOffsetDateTime.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void now_Clock_nullZoneId() { OffsetDateTime.now((ZoneId) null); }
Example 16
Source File: Main.java From Java-Coding-Problems with MIT License | 4 votes |
public static void main(String[] args) { System.out.println("Before JDK 8:"); // yyyy-MM-dd Date date = new Date(); SimpleDateFormat formatterD1 = new SimpleDateFormat("yyyy-MM-dd"); String d1 = formatterD1.format(date); System.out.println(d1); // yyyy-MM-dd HH:mm:ss SimpleDateFormat formatterD2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String d2 = formatterD2.format(date); System.out.println(d2); // E MMM yyyy HH:mm:ss.SSSZ SimpleDateFormat formatterD3 = new SimpleDateFormat("E MMM yyyy HH:mm:ss.SSSZ"); String d3 = formatterD3.format(date); System.out.println(d3); System.out.println("\nStarting with JDK 8:"); // yyyy-MM-dd LocalDate localDate = LocalDate.now(); DateTimeFormatter formatterLocalDate = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String ld1 = formatterLocalDate.format(localDate); // or shortly String ld2 = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); System.out.println(ld1); System.out.println(ld2); // HH:mm:ss LocalTime localTime = LocalTime.now(); DateTimeFormatter formatterLocalTime = DateTimeFormatter.ofPattern("HH:mm:ss"); String lt1 = formatterLocalTime.format(localTime); // or shortly String lt2 = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")); System.out.println(lt1); System.out.println(lt2); // yyyy-MM-dd HH:mm:ss LocalDateTime localDateTime = LocalDateTime.now(); DateTimeFormatter formatterLocalDateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String ldt1 = formatterLocalDateTime.format(localDateTime); // or shortly String ldt2 = LocalDateTime.now() .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); System.out.println(ldt1); System.out.println(ldt2); // E MMM yyyy HH:mm:ss.SSSZ ZonedDateTime zonedDateTime = ZonedDateTime.now(); DateTimeFormatter formatterZonedDateTime = DateTimeFormatter.ofPattern("E MMM yyyy HH:mm:ss.SSSZ"); String zdt1 = formatterZonedDateTime.format(zonedDateTime); // or shortly String zdt2 = ZonedDateTime.now() .format(DateTimeFormatter.ofPattern("E MMM yyyy HH:mm:ss.SSSZ")); System.out.println(zdt1); System.out.println(zdt2); // E MMM yyyy HH:mm:ss.SSSZ OffsetDateTime offsetDateTime = OffsetDateTime.now(); DateTimeFormatter formatterOffsetDateTime = DateTimeFormatter.ofPattern("E MMM yyyy HH:mm:ss.SSSZ"); String odt1 = formatterOffsetDateTime.format(offsetDateTime); // or shortly String odt2 = OffsetDateTime.now() .format(DateTimeFormatter.ofPattern("E MMM yyyy HH:mm:ss.SSSZ")); System.out.println(odt1); System.out.println(odt2); // HH:mm:ss,Z OffsetTime offsetTime = OffsetTime.now(); DateTimeFormatter formatterOffsetTime = DateTimeFormatter.ofPattern("HH:mm:ss,Z"); String ot1 = formatterOffsetTime.format(offsetTime); // or shortly String ot2 = OffsetTime.now() .format(DateTimeFormatter.ofPattern("HH:mm:ss,Z")); System.out.println(ot1); System.out.println(ot2); }
Example 17
Source File: TCKOffsetDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void now_Clock_nullClock() { OffsetDateTime.now((Clock) null); }
Example 18
Source File: TCKOffsetDateTime.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void now_Clock_nullClock() { OffsetDateTime.now((Clock) null); }
Example 19
Source File: GraphSONMapperEmbeddedTypeTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Test public void shouldHandleOffsetDateTime() throws Exception { final OffsetDateTime o = OffsetDateTime.now(); assertEquals(o, serializeDeserialize(mapper, o, OffsetDateTime.class)); }
Example 20
Source File: SecureDataVersionServiceTest.java From cerberus with Apache License 2.0 | 4 votes |
@Test public void test_that_getSecureDataVersionsByPath_returns_versions() { String pathToSecureData = "path to secure data"; String versionId = "version id"; String action = "action"; String sdbId = "sdb id"; String actionPrincipal = "action principal"; OffsetDateTime actionTs = OffsetDateTime.now(); String versionCreatedBy = "version created by"; OffsetDateTime versionCreatedTs = OffsetDateTime.now(); String sdbCategory = "sdb category"; String fullPath = String.format("%s/%s", sdbCategory, pathToSecureData); SecureDataVersionRecord record = new SecureDataVersionRecord() .setId(versionId) .setEncryptedBlob("encrypted blob".getBytes()) .setActionPrincipal(actionPrincipal) .setSdboxId(sdbId) .setActionTs(actionTs) .setPath(pathToSecureData) .setVersionCreatedBy(versionCreatedBy) .setVersionCreatedTs(versionCreatedTs) .setAction(action); List<SecureDataVersionRecord> versions = Lists.newArrayList(record); when(secureDataService.getSecureDataRecordForPath(sdbId, pathToSecureData)) .thenReturn(Optional.empty()); when(secureDataVersionDao.listSecureDataVersionByPath(pathToSecureData, 1, 0)) .thenReturn(versions); SecureDataVersionsResult summaries = secureDataVersionService.getSecureDataVersionSummariesByPath( sdbId, pathToSecureData, sdbCategory, 1, 0); SecureDataVersionSummary result = summaries.getSecureDataVersionSummaries().get(0); assertEquals(record.getAction(), result.getAction()); assertEquals(record.getActionPrincipal(), result.getActionPrincipal()); assertEquals(record.getActionTs(), result.getActionTs()); assertEquals(record.getSdboxId(), result.getSdboxId()); assertEquals(record.getId(), result.getId()); assertEquals(fullPath, result.getPath()); assertEquals(record.getVersionCreatedBy(), result.getVersionCreatedBy()); assertEquals(record.getVersionCreatedTs(), result.getVersionCreatedTs()); }