Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(date-fns): update date-fns to latest version #2045

Merged
merged 3 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages-smoke/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/framework/date-fns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 12 additions & 4 deletions src/framework/date-fns/services/date-fns-date.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
);
});
Expand All @@ -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();
Expand Down
16 changes: 3 additions & 13 deletions src/framework/date-fns/services/date-fns-date.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down