|
| 1 | +import {DlDateAdapterString} from '../../dl-date-adapter-string'; |
| 2 | +import {DlDateAdapter} from '../../dl-date-adapter'; |
| 3 | + |
| 4 | +import * as _moment from 'moment'; |
| 5 | +import {Moment} from 'moment'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Work around for moment namespace conflict when used with webpack and rollup. |
| 9 | + * See https://github.com/dherges/ng-packagr/issues/163 |
| 10 | + * |
| 11 | + * Depending on whether rollup is used, moment needs to be imported differently. |
| 12 | + * Since Moment.js doesn't have a default export, we normally need to import using |
| 13 | + * the `* as`syntax. |
| 14 | + * |
| 15 | + * rollup creates a synthetic default module and we thus need to import it using |
| 16 | + * the `default as` syntax. |
| 17 | + * |
| 18 | + * @internal |
| 19 | + * |
| 20 | + **/ |
| 21 | +const moment = _moment; |
| 22 | + |
| 23 | +/** |
| 24 | + * @license |
| 25 | + * Copyright 2013-present Dale Lotts All Rights Reserved. |
| 26 | + * http://www.dalelotts.com |
| 27 | + * |
| 28 | + * Use of this source code is governed by an MIT-style license that can be |
| 29 | + * found in the LICENSE file at https://github.com/dalelotts/angular-bootstrap-datetimepicker/blob/master/LICENSE |
| 30 | + */ |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +describe('DlDateAdapterString', () => { |
| 35 | + |
| 36 | + describe('default configuration', () => { |
| 37 | + let dateAdapter: DlDateAdapterString; |
| 38 | + let testMoment: Moment; |
| 39 | + beforeEach(() => { |
| 40 | + testMoment = moment(1523077200000); |
| 41 | + dateAdapter = new DlDateAdapterString([ |
| 42 | + moment.localeData().longDateFormat('lll'), |
| 43 | + 'YYYY-MM-DDTHH:mm', |
| 44 | + 'YYYY-MM-DDTHH:mm:ss', |
| 45 | + 'YYYY-MM-DDTHH:mm:ss.SSS', |
| 46 | + 'YYYY-MM-DD', |
| 47 | + 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' // ISO_8601 |
| 48 | + ], |
| 49 | + moment.localeData().longDateFormat('lll') |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('fromMilliseconds', () => { |
| 54 | + it('should return "lll" moment format', () => { |
| 55 | + expect(dateAdapter.fromMilliseconds(1523077200000)).toEqual(testMoment.format('lll')); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('toMilliseconds', () => { |
| 60 | + it('should accept "lll" moment format', () => { |
| 61 | + expect(dateAdapter.toMilliseconds(testMoment.format('lll'))).toEqual(1523077200000); |
| 62 | + }); |
| 63 | + it('should return undefined for invalid date value', () => { |
| 64 | + expect(dateAdapter.toMilliseconds('Aor 7, 2018 12:00 AM')).toBeUndefined(); |
| 65 | + }); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments