|
| 1 | +/* |
| 2 | + * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper |
| 3 | + * @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos |
| 4 | + * @license BSD-3-Clause (see LICENSE in the root directory of this source tree) |
| 5 | + */ |
| 6 | + |
| 7 | +import { expect } from 'chai'; |
| 8 | + |
| 9 | +import { |
| 10 | + Instant, LocalDateTime, ZonedDateTime, |
| 11 | + ZoneId, ZoneOffset, |
| 12 | + NullPointerException |
| 13 | +} from 'js-joda'; |
| 14 | + |
| 15 | +import { assertEquals } from '../testUtils'; |
| 16 | +import '../useMomentZoneRules'; |
| 17 | + |
| 18 | +describe('org.threeten.bp.TestLocalDateTime', () => { |
| 19 | + |
| 20 | + const OFFSET_PTWO = ZoneOffset.ofHours(2); |
| 21 | + const EUROPE_BERLIN = ZoneId.of('Europe/Berlin'); |
| 22 | + const ZONE_GAZA = ZoneId.of('Asia/Gaza'); |
| 23 | + |
| 24 | + describe('ofInstant()', () => { |
| 25 | + |
| 26 | + it('factory_ofInstant_zone()', () => { |
| 27 | + const test = LocalDateTime.ofInstant(Instant.ofEpochSecond(1451606400 + 86400 + 3600 + 120 + 4, 500), EUROPE_BERLIN); |
| 28 | + assertEquals(test, LocalDateTime.of(2016, 1, 2, 2, 2, 4, 500)); // offset +01:00 |
| 29 | + }); |
| 30 | + |
| 31 | + it('factory_ofInstant_nullInstant', () => { |
| 32 | + expect(() => { |
| 33 | + LocalDateTime.ofInstant(null, EUROPE_BERLIN); |
| 34 | + }).to.throw(NullPointerException); |
| 35 | + }); |
| 36 | + |
| 37 | + }); |
| 38 | + |
| 39 | + describe('atZone()', () => { |
| 40 | + |
| 41 | + it('test_atZone', () => { |
| 42 | + const t = LocalDateTime.of(2008, 6, 30, 11, 30); |
| 43 | + assertEquals(t.atZone(EUROPE_BERLIN), |
| 44 | + ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), EUROPE_BERLIN)); |
| 45 | + }); |
| 46 | + |
| 47 | + it('test_atZone_Offset', () => { |
| 48 | + const t = LocalDateTime.of(2008, 6, 30, 11, 30); |
| 49 | + assertEquals(t.atZone(OFFSET_PTWO), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO)); |
| 50 | + }); |
| 51 | + |
| 52 | + // TODO Fixme |
| 53 | + it.skip('test_atZone_dstGap', () => { |
| 54 | + const t = LocalDateTime.of(2007, 4, 1, 0, 0); |
| 55 | + assertEquals(t.atZone(ZONE_GAZA), |
| 56 | + ZonedDateTime.of(LocalDateTime.of(2007, 4, 1, 1, 0), ZONE_GAZA)); |
| 57 | + }); |
| 58 | + |
| 59 | + it('test_atZone_dstOverlap', () => { |
| 60 | + const t = LocalDateTime.of(2007, 10, 28, 2, 30); |
| 61 | + assertEquals(t.atZone(EUROPE_BERLIN), |
| 62 | + ZonedDateTime.ofStrict(LocalDateTime.of(2007, 10, 28, 2, 30), OFFSET_PTWO, EUROPE_BERLIN)); |
| 63 | + }); |
| 64 | + |
| 65 | + it('test_atZone_nullTimeZone', () => { |
| 66 | + expect(() => { |
| 67 | + const t = LocalDateTime.of(2008, 6, 30, 11, 30); |
| 68 | + t.atZone(null); |
| 69 | + }).to.throw(NullPointerException); |
| 70 | + }); |
| 71 | + |
| 72 | + }); |
| 73 | + |
| 74 | +}); |
0 commit comments