OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 Google Inc. | 2 * Copyright (c) 2010 Google Inc. |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.apache.org/licenses/LICENSE-2.0 | 7 * http://www.apache.org/licenses/LICENSE-2.0 |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 14 matching lines...) Expand all Loading... |
25 */ | 25 */ |
26 public class DateTimeTest extends TestCase { | 26 public class DateTimeTest extends TestCase { |
27 | 27 |
28 public DateTimeTest() { | 28 public DateTimeTest() { |
29 } | 29 } |
30 | 30 |
31 public DateTimeTest(String testName) { | 31 public DateTimeTest(String testName) { |
32 super(testName); | 32 super(testName); |
33 } | 33 } |
34 | 34 |
35 public void testEquals() { | 35 public void testEquals() throws InterruptedException { |
36 assertEquals(new DateTime(1234567890L), new DateTime(1234567890L, 120)); | 36 assertFalse("Check equals with two different tz specified.", |
| 37 new DateTime(1234567890L).equals(new DateTime(1234567890L, 120))); |
37 assertTrue("Check equals with two identical tz specified.", | 38 assertTrue("Check equals with two identical tz specified.", |
38 new DateTime(1234567890L, -240).equals(new DateTime(1234567890L, -240)))
; | 39 new DateTime(1234567890L, -240).equals(new DateTime(1234567890L, -240)))
; |
39 assertTrue("Check equals with two different tz specified.", | 40 assertFalse("Check equals with two different tz specified.", |
40 new DateTime(1234567890L, 60).equals(new DateTime(1234567890L, 240))); | 41 new DateTime(1234567890L, 60).equals(new DateTime(1234567890L, 240))); |
41 | 42 |
42 assertFalse("Check not equal.", new DateTime(1234567890L).equals(new DateTim
e(9876543210L))); | 43 assertFalse("Check not equal.", new DateTime(1234567890L).equals(new DateTim
e(9876543210L))); |
43 assertFalse("Check not equal with tz.", | 44 assertFalse("Check not equal with tz.", |
44 new DateTime(1234567890L, 120).equals(new DateTime(9876543210L, 120))); | 45 new DateTime(1234567890L, 120).equals(new DateTime(9876543210L, 120))); |
45 assertFalse( | 46 assertFalse( |
46 "Check not equal with Date.", new DateTime(1234567890L).equals(new Date(
9876543210L))); | 47 "Check not equal with Date.", new DateTime(1234567890L).equals(new Date(
9876543210L))); |
| 48 |
| 49 DateTime dateTime1 = new DateTime("2011-01-01"); |
| 50 Thread.sleep(10); |
| 51 DateTime dateTime2 = new DateTime("2011-01-01"); |
| 52 assertEquals(dateTime1, dateTime2); |
47 } | 53 } |
48 | 54 |
49 public void testParseRfc3339() { | 55 public void testParseRfc3339() { |
50 expectExceptionForParseRfc3339(""); | 56 expectExceptionForParseRfc3339(""); |
51 expectExceptionForParseRfc3339("abc"); | 57 expectExceptionForParseRfc3339("abc"); |
52 DateTime value = DateTime.parseRfc3339("2007-06-01"); | 58 DateTime value = DateTime.parseRfc3339("2007-06-01"); |
53 assertTrue(value.isDateOnly()); | 59 assertTrue(value.isDateOnly()); |
54 value = DateTime.parseRfc3339("2007-06-01T10:11:30.057"); | 60 value = DateTime.parseRfc3339("2007-06-01T10:11:30.057"); |
55 assertFalse(value.isDateOnly()); | 61 assertFalse(value.isDateOnly()); |
56 value = DateTime.parseRfc3339("2007-06-01T10:11:30Z"); | 62 value = DateTime.parseRfc3339("2007-06-01T10:11:30Z"); |
57 assertEquals(0, value.getValue() % 100); | 63 assertEquals(0, value.getValue() % 100); |
58 | 64 |
59 value = new DateTime("2007-06-01"); | 65 value = new DateTime("2007-06-01"); |
60 assertTrue(value.isDateOnly()); | 66 assertTrue(value.isDateOnly()); |
61 value = new DateTime("2007-06-01T10:11:30.057"); | 67 value = new DateTime("2007-06-01T10:11:30.057"); |
62 assertFalse(value.isDateOnly()); | 68 assertFalse(value.isDateOnly()); |
63 value = new DateTime("2007-06-01T10:11:30Z"); | 69 value = new DateTime("2007-06-01T10:11:30Z"); |
64 assertEquals(0, value.getValue() % 100); | 70 assertEquals(0, value.getValue() % 100); |
65 } | 71 } |
66 | 72 |
67 private void expectExceptionForParseRfc3339(String input) { | 73 private void expectExceptionForParseRfc3339(String input) { |
68 try { | 74 try { |
69 DateTime.parseRfc3339(input); | 75 DateTime.parseRfc3339(input); |
70 fail("expected NumberFormatException"); | 76 fail("expected NumberFormatException"); |
71 } catch (NumberFormatException e) { | 77 } catch (NumberFormatException e) { |
72 // expected | 78 // expected |
73 } | 79 } |
74 } | 80 } |
75 } | 81 } |
OLD | NEW |