use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method now_Clock_allSecsInDay_offset.
@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);
}
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method now_Clock_allSecsInDay_beforeEpoch.
@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);
}
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method now_Clock_allSecsInDay_utc.
//-----------------------------------------------------------------------
// now(Clock)
//-----------------------------------------------------------------------
@Test
public void now_Clock_allSecsInDay_utc() {
for (int i = 0; i < (2 * 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(), 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(), ZoneOffset.UTC);
}
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method now_Clock_offsets.
@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);
}
}
use of java.time.Clock in project sonar-java by SonarSource.
the class A method foo.
void foo() {
HijrahDate hijrahDate = HijrahDate.now();
// Noncompliant {{Synchronize on a non-value-based object; synchronizing on a "HijrahDate" could lead to contention. (sonar.java.source not set. Assuming 8 or greater.)}}
synchronized (hijrahDate) {
}
JapaneseDate japaneseDate = JapaneseDate.now();
// Noncompliant
synchronized (japaneseDate) {
}
MinguoDate minguoDate = MinguoDate.now();
// Noncompliant
synchronized (minguoDate) {
}
ThaiBuddhistDate thaiBuddhistDate = ThaiBuddhistDate.now();
// Noncompliant
synchronized (thaiBuddhistDate) {
}
LocalDateTime localDateTime = LocalDateTime.now();
// Noncompliant
synchronized (localDateTime) {
}
Optional<Object> optionalEmpty = Optional.empty();
// Noncompliant {{Synchronize on a non-value-based object; synchronizing on a "Optional" could lead to contention. (sonar.java.source not set. Assuming 8 or greater.)}}
synchronized (optionalEmpty) {
}
OptionalDouble optionalDouble = OptionalDouble.empty();
// Noncompliant
synchronized (optionalDouble) {
}
OptionalLong optionalLong = OptionalLong.empty();
// Noncompliant
synchronized (optionalLong) {
}
OptionalInt optionalInt = OptionalInt.empty();
// Noncompliant
synchronized (optionalInt) {
}
Clock clock = Clock.systemUTC();
// Compliant
synchronized (clock) {
}
Object object = new Object();
// Compliant
synchronized (object) {
}
DateTimeFormatterBuilder dateTimeFormatter = new DateTimeFormatterBuilder();
// Compliant - not part of 'java.time' package but subpackage 'java.time.format'
synchronized (dateTimeFormatter) {
}
// Compliant
synchronized (unknownObject) {
}
}
Aggregations