|
1 |
| -import org.scalatest._ |
2 |
| -import java.util.{TimeZone, GregorianCalendar} |
| 1 | +import java.time.LocalDate |
| 2 | +import java.time.LocalDateTime |
| 3 | +import java.time.format.DateTimeFormatter |
| 4 | + |
| 5 | +import org.scalatest.FunSuite |
| 6 | +import org.scalatest.Matchers |
3 | 7 |
|
4 | 8 | class GigasecondTests extends FunSuite with Matchers {
|
5 |
| - test ("1") { |
6 |
| - // Note: Months are 0-indexed. 3 = April |
7 |
| - val cal = new GregorianCalendar(2011, 3, 25) |
8 |
| - cal.setTimeZone(TimeZone.getTimeZone("GMT")) |
9 |
| - val gs = Gigasecond(cal) |
10 |
| - |
11 |
| - val expected = new GregorianCalendar(2043, 0, 1, 1, 46, 40) |
12 |
| - expected.setTimeZone(TimeZone.getTimeZone("GMT")) |
13 |
| - gs.date should be (expected) |
14 |
| - } |
15 | 9 |
|
16 |
| - test ("2") { |
17 |
| - pending |
18 |
| - val cal = new GregorianCalendar(1977, 5, 13) |
19 |
| - cal.setTimeZone(TimeZone.getTimeZone("GMT")) |
20 |
| - val gs = Gigasecond(cal) |
| 10 | + private def dateTime(str: String): LocalDateTime = |
| 11 | + LocalDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(str)) |
| 12 | + |
| 13 | + private def date(str: String): LocalDate = |
| 14 | + LocalDate.from(DateTimeFormatter.ISO_DATE.parse(str)) |
| 15 | + |
21 | 16 |
|
22 |
| - val expected = new GregorianCalendar(2009, 1, 19, 1, 46, 40) |
23 |
| - expected.setTimeZone(TimeZone.getTimeZone("GMT")) |
24 |
| - gs.date should be (expected) |
| 17 | + test("modern time") { |
| 18 | + val input = date("2011-04-25") |
| 19 | + val expected = dateTime("2043-01-01T01:46:40") |
| 20 | + Gigasecond.addGigaseconds(input) should be (expected) |
25 | 21 | }
|
26 | 22 |
|
27 |
| - test ("3") { |
| 23 | + test("after epoch time") { |
28 | 24 | pending
|
29 |
| - val cal = new GregorianCalendar(1959, 6, 19) |
30 |
| - cal.setTimeZone(TimeZone.getTimeZone("GMT")) |
31 |
| - val gs = Gigasecond(cal) |
| 25 | + val input = date("1977-06-13") |
| 26 | + val expected = dateTime("2009-02-19T01:46:40") |
| 27 | + Gigasecond.addGigaseconds(input) should be (expected) |
| 28 | + } |
32 | 29 |
|
33 |
| - val expected = new GregorianCalendar(1991, 2, 27, 1, 46, 40) |
34 |
| - expected.setTimeZone(TimeZone.getTimeZone("GMT")) |
35 |
| - gs.date should be (expected) |
| 30 | + test("before epoch time") { |
| 31 | + pending |
| 32 | + val input = date("1959-07-19") |
| 33 | + val expected = dateTime("1991-03-27T01:46:40") |
| 34 | + Gigasecond.addGigaseconds(input) should be (expected) |
36 | 35 | }
|
37 | 36 |
|
38 |
| - test ("4") { |
| 37 | + test("full time specified") { |
39 | 38 | pending
|
40 |
| - val cal = new GregorianCalendar(2015, 0, 24, 23, 59, 59) |
41 |
| - cal.setTimeZone(TimeZone.getTimeZone("GMT")) |
42 |
| - val gs = Gigasecond(cal) |
| 39 | + val input = dateTime("2015-01-24T22:00:00") |
| 40 | + val expected = dateTime("2046-10-02T23:46:40") |
| 41 | + Gigasecond.addGigaseconds(input) should be (expected) |
| 42 | + } |
43 | 43 |
|
44 |
| - val expected = new GregorianCalendar(2046, 9, 3, 1, 46, 39) |
45 |
| - expected.setTimeZone(TimeZone.getTimeZone("GMT")) |
46 |
| - gs.date should be (expected) |
| 44 | + test("full time with day roll-over") { |
| 45 | + pending |
| 46 | + val input = dateTime("2015-01-24T23:59:59") |
| 47 | + val expected = dateTime("2046-10-03T01:46:39") |
| 48 | + Gigasecond.addGigaseconds(input) should be (expected) |
47 | 49 | }
|
48 | 50 |
|
49 |
| - test ("yourself") { |
| 51 | + test("your birthday") { |
50 | 52 | pending
|
51 |
| - // val yourBirthday = new GregorianCalendar(year, month-1, day) |
52 |
| - // val gs = Gigasecond(yourBirthday) |
53 |
| - // gs.date should be (new GregorianCalendar(2009, 0, 31, 0, 46, 40)) |
| 53 | + val yourBirthday = date(???) |
| 54 | + val expected = dateTime(???) |
| 55 | + Gigasecond.addGigaseconds(yourBirthday) should be (expected) |
54 | 56 | }
|
55 | 57 | }
|
0 commit comments