Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add now(ZoneId)

Consistent with local classes
  • Loading branch information...
commit 704c0cf94bfab393c8ef4655816cada9027cc1c3 1 parent 35c6d32
@jodastephen jodastephen authored
View
16 src/main/java/javax/time/OffsetDate.java
@@ -109,6 +109,22 @@ public static OffsetDate now() {
}
/**
+ * Obtains the current date from the system clock in the specified time-zone.
+ * <p>
+ * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
+ * Specifying the time-zone avoids dependence on the default time-zone.
+ * The offset will be calculated from the specified time-zone.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @return the current date using the system clock, not null
+ */
+ public static OffsetDate now(ZoneId zone) {
+ return now(Clock.system(zone));
+ }
+
+ /**
* Obtains the current date from the specified clock.
* <p>
* This will query the specified clock to obtain the current date - today.
View
16 src/main/java/javax/time/OffsetDateTime.java
@@ -110,6 +110,22 @@ public static OffsetDateTime now() {
}
/**
+ * Obtains the current date-time from the system clock in the specified time-zone.
+ * <p>
+ * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date-time.
+ * Specifying the time-zone avoids dependence on the default time-zone.
+ * The offset will be calculated from the specified time-zone.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @return the current date-time using the system clock, not null
+ */
+ public static OffsetDateTime now(ZoneId zone) {
+ return now(Clock.system(zone));
+ }
+
+ /**
* Obtains the current date-time from the specified clock.
* <p>
* This will query the specified clock to obtain the current date-time.
View
16 src/main/java/javax/time/OffsetTime.java
@@ -108,6 +108,22 @@ public static OffsetTime now() {
}
/**
+ * Obtains the current time from the system clock in the specified time-zone.
+ * <p>
+ * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current time.
+ * Specifying the time-zone avoids dependence on the default time-zone.
+ * The offset will be calculated from the specified time-zone.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @return the current time using the system clock, not null
+ */
+ public static OffsetTime now(ZoneId zone) {
+ return now(Clock.system(zone));
+ }
+
+ /**
* Obtains the current time from the specified clock.
* <p>
* This will query the specified clock to obtain the current time.
View
16 src/main/java/javax/time/ZonedDateTime.java
@@ -120,6 +120,22 @@ public static ZonedDateTime now() {
}
/**
+ * Obtains the current date-time from the system clock in the specified time-zone.
+ * <p>
+ * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date-time.
+ * Specifying the time-zone avoids dependence on the default time-zone.
+ * The offset will be calculated from the specified time-zone.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @return the current date-time using the system clock, not null
+ */
+ public static ZonedDateTime now(ZoneId zone) {
+ return now(Clock.system(zone));
+ }
+
+ /**
* Obtains the current date-time from the specified clock.
* <p>
* This will query the specified clock to obtain the current date-time.
View
10 src/tck/java/javax/time/TCKOffsetDate.java
@@ -221,6 +221,16 @@ public void now_Clock_offsets() {
}
}
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void now_Clock_nullZoneId() {
+ OffsetDate.now((ZoneId) null);
+ }
+
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void now_Clock_nullClock() {
+ OffsetDate.now((Clock) null);
+ }
+
//-----------------------------------------------------------------------
// factories
//-----------------------------------------------------------------------
View
15 src/tck/java/javax/time/TCKOffsetDateTime.java
@@ -220,11 +220,6 @@ public void now() {
//-----------------------------------------------------------------------
// now(Clock)
//-----------------------------------------------------------------------
- @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
- public void now_Clock_nullClock() {
- OffsetDateTime.now(null);
- }
-
@Test(groups={"tck"})
public void now_Clock_allSecsInDay_utc() {
for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
@@ -290,6 +285,16 @@ public void now_Clock_offsets() {
}
}
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void now_Clock_nullZoneId() {
+ OffsetDateTime.now((ZoneId) null);
+ }
+
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void now_Clock_nullClock() {
+ OffsetDateTime.now((Clock) null);
+ }
+
//-----------------------------------------------------------------------
private void check(OffsetDateTime test, int y, int mo, int d, int h, int m, int s, int n, ZoneOffset offset) {
assertEquals(test.getYear(), y);
View
15 src/tck/java/javax/time/TCKOffsetTime.java
@@ -179,11 +179,6 @@ public void now() {
//-----------------------------------------------------------------------
// now(Clock)
//-----------------------------------------------------------------------
- @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
- public void now_Clock_nullClock() {
- OffsetTime.now(null);
- }
-
@Test(groups={"tck"})
public void now_Clock_allSecsInDay() {
for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
@@ -227,6 +222,16 @@ public void now_Clock_offsets() {
}
}
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void now_Clock_nullZoneId() {
+ OffsetTime.now((ZoneId) null);
+ }
+
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void now_Clock_nullClock() {
+ OffsetTime.now((Clock) null);
+ }
+
//-----------------------------------------------------------------------
// factories
//-----------------------------------------------------------------------
View
8 src/test/java/javax/time/TestOffsetDate.java
@@ -143,14 +143,6 @@ public void test_interfaces() {
}
//-----------------------------------------------------------------------
- // now(Clock)
- //-----------------------------------------------------------------------
- @Test(expectedExceptions=NullPointerException.class, groups={"implementation"})
- public void now_Clock_nullClock() {
- OffsetDate.now(null);
- }
-
- //-----------------------------------------------------------------------
// factories
//-----------------------------------------------------------------------
void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) {
Please sign in to comment.
Something went wrong with that request. Please try again.