diff --git a/package-lock.json b/package-lock.json index 33f1571424..ac8df6d987 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5255,9 +5255,9 @@ } }, "date-fns": { - "version": "2.0.0-alpha.27", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.0.0-alpha.27.tgz", - "integrity": "sha512-cqfVLS+346P/Mpj2RpDrBv0P4p2zZhWWvfY5fuWrXNR/K38HaAGEkeOwb47hIpQP9Jr/TIxjZ2/sNMQwdXuGMg==" + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.6.0.tgz", + "integrity": "sha512-F55YxqRdEfP/eYQmQjLN798v0AwLjmZ8nMBjdQvNwEE3N/zWVrlkkqT+9seBlPlsbkybG4JmWg3Ee3dIV9BcGQ==" }, "date-now": { "version": "0.1.4", diff --git a/package.json b/package.json index ea405c34bb..e8b4f5de5b 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "bootstrap": "4.0.0", "colors.js": "1.2.4", "core-js": "2.5.7", - "date-fns": ">=2.0.0-alpha.16 <=2.0.0-alpha.27", + "date-fns": "2", "docsearch.js": "^2.5.2", "eva-icons": "^1.1.2", "gulp-bump": "2.7.0", diff --git a/packages-smoke/package.json b/packages-smoke/package.json index cddbfaaf81..1d67487660 100644 --- a/packages-smoke/package.json +++ b/packages-smoke/package.json @@ -34,7 +34,7 @@ "@nguniversal/express-engine": "^8.1.1", "@nguniversal/module-map-ngfactory-loader": "8.1.1", "core-js": "^2.5.7", - "date-fns": "^2.0.0-alpha.27", + "date-fns": "2", "eva-icons": "1.1.2", "express": "^4.15.2", "moment": "^2.22.2", diff --git a/src/framework/date-fns/package.json b/src/framework/date-fns/package.json index df26501d25..b5c705ab22 100644 --- a/src/framework/date-fns/package.json +++ b/src/framework/date-fns/package.json @@ -22,7 +22,7 @@ ], "peerDependencies": { "@nebular/theme": "4.6.0", - "date-fns": ">=2.0.0-alpha.16 <=2.0.0-alpha.27" + "date-fns": "2" }, "sideEffects": false } diff --git a/src/framework/date-fns/services/date-fns-date.service.spec.ts b/src/framework/date-fns/services/date-fns-date.service.spec.ts index b4a886d5e9..d71459a1eb 100644 --- a/src/framework/date-fns/services/date-fns-date.service.spec.ts +++ b/src/framework/date-fns/services/date-fns-date.service.spec.ts @@ -44,8 +44,14 @@ describe('date-fns-date-service', () => { TestBed.get(LOCALE_ID), { format: FORMAT, - parseOptions: { awareOfUnicodeTokens: true }, - formatOptions: { awareOfUnicodeTokens: true }, + parseOptions: { + useAdditionalWeekYearTokens: true, + useAdditionalDayOfYearTokens: true, + }, + formatOptions: { + useAdditionalWeekYearTokens: true, + useAdditionalDayOfYearTokens: true, + }, }, ); }); @@ -65,14 +71,16 @@ describe('date-fns-date-service', () => { }); it('should pass parseOptions to parse function', () => { - // date-fns require { awareOfUnicodeTokens: true } option to be passed to parse function + // date-fns require { useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true } options + // to be passed to parse function // when format contains 'DD' or 'YYYY' tokens, otherwise it throws. This option is // passed as global config to service constructor so it shouldn't throw. expect(() => dateService.parse(formattedDate, 'DD/MM/YYYY')).not.toThrow(); }); it('should pass formatOptions to format function', () => { - // date-fns require { awareOfUnicodeTokens: true } option to be passed to format function + // date-fns require { useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true } options + // to be passed to format function // when format contains 'DD' or 'YYYY' tokens, otherwise it throws. This option is // passed as global config to service constructor so it shouldn't throw. expect(() => dateService.format(date, 'DD/MM/YYYY')).not.toThrow(); diff --git a/src/framework/date-fns/services/date-fns-date.service.ts b/src/framework/date-fns/services/date-fns-date.service.ts index bfe2650acd..23cca2514f 100644 --- a/src/framework/date-fns/services/date-fns-date.service.ts +++ b/src/framework/date-fns/services/date-fns-date.service.ts @@ -8,19 +8,9 @@ import { Inject, Injectable, LOCALE_ID, Optional } from '@angular/core'; import { NB_DATE_SERVICE_OPTIONS, NbNativeDateService } from '@nebular/theme'; -import * as dateFnsParse from 'date-fns/parse'; -// @ts-ignore -import { default as rollupParse } from 'date-fns/parse'; -import * as dateFnsFormat from 'date-fns/format'; -// @ts-ignore -import { default as rollupFormat } from 'date-fns/format'; -import * as dateFnsGetWeek from 'date-fns/getWeek'; -// @ts-ignore -import { default as rollupGetWeek } from 'date-fns/getWeek'; - -const parse = rollupParse || dateFnsParse; -const formatDate = rollupFormat || dateFnsFormat; -const getWeek = rollupGetWeek || dateFnsGetWeek; +import { default as parse } from 'date-fns/parse'; +import { default as formatDate } from 'date-fns/format'; +import { default as getWeek } from 'date-fns/getWeek'; export interface NbDateFnsOptions { format: string; diff --git a/src/framework/theme/components/datepicker/datepicker.directive.ts b/src/framework/theme/components/datepicker/datepicker.directive.ts index bb203dd93e..1ff97f4f2f 100644 --- a/src/framework/theme/components/datepicker/datepicker.directive.ts +++ b/src/framework/theme/components/datepicker/datepicker.directive.ts @@ -206,13 +206,14 @@ export const NB_DATE_SERVICE_OPTIONS = new InjectionToken('Date service options' * Also format can be set globally with `NbDateFnsDateModule.forRoot({ format: 'dd.MM.yyyy' })` and * `NbDateFnsDateModule.forChild({ format: 'dd.MM.yyyy' })` methods. * - * Please note to use some of the formatting tokens you also need to pass `{ awareOfUnicodeTokens: true }` to date-fns - * parse and format functions. You can configure options passed this functions by setting `formatOptions` and + * Please note to use some of the formatting tokens you also need to pass + * `{ useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true }` to date-fns parse and format functions. + * You can configure options passed this functions by setting `formatOptions` and * `parseOptions` of options object passed to `NbDateFnsDateModule.forRoot` and `NbDateFnsDateModule.forChild` methods. * ```ts * NbDateFnsDateModule.forRoot({ - * parseOptions: { awareOfUnicodeTokens: true }, - * formatOptions: { awareOfUnicodeTokens: true }, + * parseOptions: { useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true }, + * formatOptions: { useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true }, * }) * ``` * Further info on `date-fns` formatting tokens could be found at