Java Code Examples for java.time.ZoneOffset#of()
The following examples show how to use
java.time.ZoneOffset#of() .
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: TCKZoneOffset.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_hours_minutes_colon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) { String str = (i < 0 || j < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + ":" + Integer.toString(Math.abs(j) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, 0); } } } ZoneOffset test1 = ZoneOffset.of("-18:00"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+18:00"); doTestOffset(test2, 18, 0, 0); }
Example 2
Source File: TCKZoneOffset.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void test_factory_string_hours_minutes_seconds_colon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { for (int k = -59; k <= 59; k++) { if ((i < 0 && j <= 0 && k <= 0) || (i > 0 && j >= 0 && k >= 0) || (i == 0 && ((j < 0 && k <= 0) || (j > 0 && k >= 0) || j == 0))) { String str = (i < 0 || j < 0 || k < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + ":" + Integer.toString(Math.abs(j) + 100).substring(1) + ":" + Integer.toString(Math.abs(k) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, k); } } } } ZoneOffset test1 = ZoneOffset.of("-18:00:00"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+18:00:00"); doTestOffset(test2, 18, 0, 0); }
Example 3
Source File: TCKZoneOffset.java From hottub with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_hours_minutes_colon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) { String str = (i < 0 || j < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + ":" + Integer.toString(Math.abs(j) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, 0); } } } ZoneOffset test1 = ZoneOffset.of("-18:00"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+18:00"); doTestOffset(test2, 18, 0, 0); }
Example 4
Source File: TCKZoneOffset.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_hours_minutes_colon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) { String str = (i < 0 || j < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + ":" + Integer.toString(Math.abs(j) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, 0); } } } ZoneOffset test1 = ZoneOffset.of("-18:00"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+18:00"); doTestOffset(test2, 18, 0, 0); }
Example 5
Source File: TCKZoneOffset.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_invalid() { String[] values = new String[] { "","A","B","C","D","E","F","G","H","I","J","K","L","M", "N","O","P","Q","R","S","T","U","V","W","X","Y","ZZ", "0", "+0:00","+00:0","+0:0", "+000","+00000", "+0:00:00","+00:0:00","+00:00:0","+0:0:0","+0:0:00","+00:0:0","+0:00:0", "1", "+01_00","+01;00","+01@00","+01:AA", "+19","+19:00","+18:01","+18:00:01","+1801","+180001", "-0:00","-00:0","-0:0", "-000","-00000", "-0:00:00","-00:0:00","-00:00:0","-0:0:0","-0:0:00","-00:0:0","-0:00:0", "-19","-19:00","-18:01","-18:00:01","-1801","-180001", "-01_00","-01;00","-01@00","-01:AA", "@01:00", }; for (int i = 0; i < values.length; i++) { try { ZoneOffset.of(values[i]); fail("Should have failed:" + values[i]); } catch (DateTimeException ex) { // expected } } }
Example 6
Source File: TCKZoneOffset.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_hours_minutes_noColon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) { String str = (i < 0 || j < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + Integer.toString(Math.abs(j) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, 0); } } } ZoneOffset test1 = ZoneOffset.of("-1800"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+1800"); doTestOffset(test2, 18, 0, 0); }
Example 7
Source File: TCKZoneOffset.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_hours_minutes_noColon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) { String str = (i < 0 || j < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + Integer.toString(Math.abs(j) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, 0); } } } ZoneOffset test1 = ZoneOffset.of("-1800"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+1800"); doTestOffset(test2, 18, 0, 0); }
Example 8
Source File: TCKZoneOffset.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_hours_minutes_colon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) { String str = (i < 0 || j < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + ":" + Integer.toString(Math.abs(j) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, 0); } } } ZoneOffset test1 = ZoneOffset.of("-18:00"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+18:00"); doTestOffset(test2, 18, 0, 0); }
Example 9
Source File: ZoneOffSetDeserializerIT.java From bootique with Apache License 2.0 | 5 votes |
@Test public void testDeserialization02() throws Exception { ZoneOffset zoneOffset = ZoneOffset.of("+17:10"); ZoneOffset value = deserialize(ZoneOffset.class, "\"" + zoneOffset.toString() + "\""); assertNotNull(value); assertEquals(zoneOffset, value); }
Example 10
Source File: TCKZoneRules.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_preTimeZones() { ZoneRules test = americaNewYork(); ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC); Instant instant = old.toInstant(); ZoneOffset offset = ZoneOffset.of("-04:56:02"); assertEquals(test.getOffset(instant), offset); checkOffset(test, old.toLocalDateTime(), offset, 1); assertEquals(test.getStandardOffset(instant), offset); assertEquals(test.getDaylightSavings(instant), Duration.ZERO); assertEquals(test.isDaylightSavings(instant), false); }
Example 11
Source File: TCKZoneRules.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_preTimeZones() { ZoneRules test = americaNewYork(); ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC); Instant instant = old.toInstant(); ZoneOffset offset = ZoneOffset.of("-04:56:02"); assertEquals(test.getOffset(instant), offset); checkOffset(test, old.toLocalDateTime(), offset, 1); assertEquals(test.getStandardOffset(instant), offset); assertEquals(test.getDaylightSavings(instant), Duration.ZERO); assertEquals(test.isDaylightSavings(instant), false); }
Example 12
Source File: TCKZoneId.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="prefixValid") public void test_prefixOfOffset(String prefix, String offset) { ZoneOffset zoff = ZoneOffset.of(offset); ZoneId zoneId = ZoneId.ofOffset(prefix, zoff); assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff); }
Example 13
Source File: TCKZoneOffset.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_factory_string_UTC() { String[] values = new String[] { "Z", "+0", "+00","+0000","+00:00","+000000","+00:00:00", "-00","-0000","-00:00","-000000","-00:00:00", }; for (int i = 0; i < values.length; i++) { ZoneOffset test = ZoneOffset.of(values[i]); assertSame(test, ZoneOffset.UTC); } }
Example 14
Source File: TCKZoneOffset.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test public void test_factory_string_UTC() { String[] values = new String[] { "Z", "+0", "+00","+0000","+00:00","+000000","+00:00:00", "-00","-0000","-00:00","-000000","-00:00:00", }; for (int i = 0; i < values.length; i++) { ZoneOffset test = ZoneOffset.of(values[i]); assertSame(test, ZoneOffset.UTC); } }
Example 15
Source File: ZoneOffsetConverterTestCase.java From commons-beanutils with Apache License 2.0 | 5 votes |
public void testSimpleConversion() throws Exception { final String[] message= { "from String", "from String", "from String", "from String", "from String", "from String", "from String", "from String", }; final Object[] input = { "-12:00", "+14:00", "+02:00" }; final ZoneOffset[] expected = { ZoneOffset.of("-12:00"), ZoneOffset.of("+14:00"), ZoneOffset.of("+02:00") }; for(int i=0;i<expected.length;i++) { assertEquals(message[i] + " to URI",expected[i],converter.convert(ZoneOffset.class,input[i])); assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i])); } for(int i=0;i<expected.length;i++) { assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i])); } }
Example 16
Source File: TCKZoneOffset.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_factory_string_hours() { for (int i = -18; i <= 18; i++) { String str = (i < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, 0, 0); } }
Example 17
Source File: MaterializedResult.java From presto with Apache License 2.0 | 5 votes |
private static ZoneOffset toZoneOffset(TimeZoneKey timeZoneKey) { requireNonNull(timeZoneKey, "timeZoneKey is null"); if (Objects.equals("UTC", timeZoneKey.getId())) { return ZoneOffset.UTC; } checkArgument(timeZoneKey.getId().matches("[+-]\\d\\d:\\d\\d"), "Not a zone-offset timezone: %s", timeZoneKey); return ZoneOffset.of(timeZoneKey.getId()); }
Example 18
Source File: TCKZoneRules.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void test_NewYork_preTimeZones() { ZoneRules test = americaNewYork(); ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC); Instant instant = old.toInstant(); ZoneOffset offset = ZoneOffset.of("-04:56:02"); assertEquals(test.getOffset(instant), offset); checkOffset(test, old.toLocalDateTime(), offset, 1); assertEquals(test.getStandardOffset(instant), offset); assertEquals(test.getDaylightSavings(instant), Duration.ZERO); assertEquals(test.isDaylightSavings(instant), false); }
Example 19
Source File: JavaTimeSerializersV2d0.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public ZoneOffset parse(final String val) { return ZoneOffset.of(val); }
Example 20
Source File: TCKZoneId.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class) public void test_invalidPrefixOfOffset(String prefix, String offset) { ZoneOffset zoff = ZoneOffset.of(offset); ZoneId zoneId = ZoneId.ofOffset(prefix, zoff); fail("should have thrown an exception for prefix: " + prefix); }