From f287992ea3180aa678516e5ab606afa731f62b89 Mon Sep 17 00:00:00 2001 From: iamkun Date: Wed, 6 Nov 2019 15:05:44 +0800 Subject: [PATCH 01/10] chore: Update changelog --- .travis.yml | 2 +- CHANGELOG.md | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e155eab66..5f28442a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ script: - codecov after_success: - if [ "$TRAVIS_BRANCH" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then - npx travis-deploy-once && npm run build && npm run babel && npm install -g @semantic-release/changelog @semantic-release/git semantic-release && semantic-release && npm run test:sauce; + npx travis-deploy-once --pro && npm run build && npm run babel && npm install -g @semantic-release/changelog @semantic-release/git semantic-release && semantic-release && npm run test:sauce; fi branches: except: diff --git a/CHANGELOG.md b/CHANGELOG.md index ea3905bed..43c7d78ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## [1.8.17](https://github.com/iamkun/dayjs/compare/v1.8.16...v1.8.17) (2019-11-06) + + +### Bug Fixes + +* Fix set utcOffset in utc mode ([d148115](https://github.com/iamkun/dayjs/commit/d148115dad8f1a5afc0a64e9b8163dfeba4616b6)) +* Update advancedFormat plugin to support w ww wo week tokens … ([#678](https://github.com/iamkun/dayjs/issues/678)) ([26cfa63](https://github.com/iamkun/dayjs/commit/26cfa63a524b803f7966dac5464f9cbf8f63387e)), closes [#676](https://github.com/iamkun/dayjs/issues/676) +* Update ka locale weekdays ([f8ca3d4](https://github.com/iamkun/dayjs/commit/f8ca3d4ba1d3cbe41613d3909c0627935a51a0c4)) +* Update nb locale ([#679](https://github.com/iamkun/dayjs/issues/679)) ([1063b0e](https://github.com/iamkun/dayjs/commit/1063b0e1b5c19a1354d233cc0f21438e7073233a)) +* Update Polish locale (pl)([#713](https://github.com/iamkun/dayjs/issues/713)) ([30d2f02](https://github.com/iamkun/dayjs/commit/30d2f026b47188833a4f44fee4bab52467d4a718)) +* Update Ukrainian locale (uk) ([#710](https://github.com/iamkun/dayjs/issues/710)) ([360161c](https://github.com/iamkun/dayjs/commit/360161cac75f597fdd51d9d1ff138601282a1b4b)) +* UTC plugin set utcOffset value ([#668](https://github.com/iamkun/dayjs/issues/668)) ([8877883](https://github.com/iamkun/dayjs/commit/88778838e71dd309e79cd1a8094d5bea36ca3390)) + ## [1.8.16](https://github.com/iamkun/dayjs/compare/v1.8.15...v1.8.16) (2019-08-27) From 5b53e98c0a3ba0eb9573a9c77caeb907439be9e7 Mon Sep 17 00:00:00 2001 From: Guido Lodetti Date: Mon, 11 Nov 2019 10:12:55 +0100 Subject: [PATCH 02/10] fix: Update Italian locale (it) (#727) --- src/locale/it.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale/it.js b/src/locale/it.js index 06e802e03..d0cdbe313 100644 --- a/src/locale/it.js +++ b/src/locale/it.js @@ -18,7 +18,7 @@ const locale = { }, relativeTime: { future: 'tra %s', - past: 'da %s', + past: '%s fa', s: 'qualche secondo', m: 'un minuto', mm: '%d minuti', From 9ad2e47e0569b23991bb0d5578f49c792c12df08 Mon Sep 17 00:00:00 2001 From: AmirAshkan Safiallah Date: Thu, 14 Nov 2019 08:12:53 -0800 Subject: [PATCH 03/10] fix: Update locale (fa) (#733) --- src/locale/fa.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/locale/fa.js b/src/locale/fa.js index 9ba95a6c3..1c2ddad12 100644 --- a/src/locale/fa.js +++ b/src/locale/fa.js @@ -5,6 +5,7 @@ const locale = { weekdays: 'یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه'.split('_'), weekdaysShort: 'یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_جمعه_شنبه'.split('_'), weekdaysMin: 'ی_د_س_چ_پ_ج_ش'.split('_'), + weekStart: 6, months: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'), monthsShort: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'), ordinal: n => n, From e31e54414fb90e1f54da13a117748ba37f52645d Mon Sep 17 00:00:00 2001 From: BH-M87 Date: Fri, 15 Nov 2019 16:23:56 +0800 Subject: [PATCH 04/10] fix: Update locale (zh-cn) (#706) --- src/locale/zh-cn.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/locale/zh-cn.js b/src/locale/zh-cn.js index 23f82e26a..3e01f2382 100644 --- a/src/locale/zh-cn.js +++ b/src/locale/zh-cn.js @@ -42,7 +42,8 @@ const locale = { MM: '%d 个月', y: '1 年', yy: '%d 年' - } + }, + meridiem: hour => (hour < 12 ? '上午' : '下午') } dayjs.locale(locale, null, true) From 15d1b813e7faf5a1f9d1ea6fc673fd27ac49d8b1 Mon Sep 17 00:00:00 2001 From: iamkun Date: Mon, 9 Dec 2019 02:43:46 +0800 Subject: [PATCH 05/10] fix: Update locale (zh-cn) meridiem (#735) --- src/locale/zh-cn.js | 16 +++++++++++++++- test/locale/zh-cn.test.js | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/locale/zh-cn.test.js diff --git a/src/locale/zh-cn.js b/src/locale/zh-cn.js index 3e01f2382..f15951751 100644 --- a/src/locale/zh-cn.js +++ b/src/locale/zh-cn.js @@ -43,7 +43,21 @@ const locale = { y: '1 年', yy: '%d 年' }, - meridiem: hour => (hour < 12 ? '上午' : '下午') + meridiem: (hour, minute) => { + const hm = (hour * 100) + minute + if (hm < 600) { + return '凌晨' + } else if (hm < 900) { + return '早上' + } else if (hm < 1130) { + return '上午' + } else if (hm < 1230) { + return '中午' + } else if (hm < 1800) { + return '下午' + } + return '晚上' + } } dayjs.locale(locale, null, true) diff --git a/test/locale/zh-cn.test.js b/test/locale/zh-cn.test.js new file mode 100644 index 000000000..7bde81e67 --- /dev/null +++ b/test/locale/zh-cn.test.js @@ -0,0 +1,21 @@ +import moment from 'moment' +import MockDate from 'mockdate' +import dayjs from '../../src' +import '../../src/locale/zh-cn' + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +it('Meridiem', () => { + const dayjsObj = dayjs().locale('zh-cn') + const momentObj = moment().locale('zh-cn') + for (let i = 0; i <= 24; i += 1) { + expect(dayjsObj.add(i, 'hour').format('A')) + .toEqual(momentObj.clone().add(i, 'hour').format('A')) + } +}) From 49670d5ae31e4e21636cc5a8bfe35fef0f6d9e4a Mon Sep 17 00:00:00 2001 From: iamkun Date: Mon, 9 Dec 2019 02:50:27 +0800 Subject: [PATCH 06/10] fix: Update Swedish locale (sv) fix ordinal error (#745) fix #743 --- src/locale/sv.js | 2 +- test/locale/sv.test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/locale/sv.test.js diff --git a/src/locale/sv.js b/src/locale/sv.js index 288c953d3..cd2d46451 100644 --- a/src/locale/sv.js +++ b/src/locale/sv.js @@ -11,7 +11,7 @@ const locale = { ordinal: (n) => { const b = n % 10 const o = (b === 1) || (b === 2) ? 'a' : 'e' - return `${n}${o}` + return `[${n}${o}]` }, formats: { LT: 'HH:mm', diff --git a/test/locale/sv.test.js b/test/locale/sv.test.js new file mode 100644 index 000000000..31c15660f --- /dev/null +++ b/test/locale/sv.test.js @@ -0,0 +1,21 @@ +import MockDate from 'mockdate' +import dayjs from '../../src' +import advancedFormat from '../../src/plugin/advancedFormat' +import '../../src/locale/sv' + +dayjs.extend(advancedFormat) + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +it('Swedish locale Do 1a not format to 1am', () => { + expect(dayjs('2019-01-01').locale('sv').format('dddd Do MMMM')) + .toBe('tisdag 1a januari') + expect(dayjs('2019-01-02').locale('sv').format('dddd Do MMMM')) + .toBe('onsdag 2a januari') +}) From cde5d0b91be7b2f5f3098de4aa0b9a4f0f28ea5c Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Dec 2019 17:40:18 +0800 Subject: [PATCH 07/10] fix(): Add missing locale type definition (#716) --- .gitignore | 4 ++-- types/index.d.ts | 8 +++++--- types/locale/index.d.ts | 11 +++++++++++ types/locale/types.d.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 types/locale/index.d.ts create mode 100644 types/locale/types.d.ts diff --git a/.gitignore b/.gitignore index d022dbedb..7894e3925 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,9 @@ coverage # build /locale /plugin -dayjs.min.js +/dayjs.min.js /esm -index.d.ts +/index.d.ts #dev demo.js diff --git a/types/index.d.ts b/types/index.d.ts index ff664da55..a0f38c89d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,3 +1,5 @@ +/// + export = dayjs; declare function dayjs (date?: dayjs.ConfigType, option?: dayjs.OptionType, locale?: string): dayjs.Dayjs @@ -91,18 +93,18 @@ declare namespace dayjs { locale(): string - locale(preset: string | { name: string, [key: string]: any }, object?: { [key: string]: any }): Dayjs + locale(preset: string | ILocale, object?: Partial): Dayjs } export type PluginFunc = (option: any, c: typeof Dayjs, d: typeof dayjs) => void export function extend(plugin: PluginFunc, option?: any): Dayjs - export function locale(preset: string | { name: string, [key: string]: any }, object?: { [key: string]: any }, isLocal?: boolean): string + export function locale(preset: string | ILocale, object?: Partial, isLocal?: boolean): string export function isDayjs(d: any): d is Dayjs export function unix(t: number): Dayjs - const Ls : { [key: string] : { [key: string]: any } } + const Ls : { [key: string] : ILocale } } diff --git a/types/locale/index.d.ts b/types/locale/index.d.ts new file mode 100644 index 000000000..bd2dca2cd --- /dev/null +++ b/types/locale/index.d.ts @@ -0,0 +1,11 @@ +/// + +declare module 'dayjs/locale/*' { + namespace locale { + interface Locale extends ILocale {} + } + + const locale: locale.Locale + + export = locale +} diff --git a/types/locale/types.d.ts b/types/locale/types.d.ts new file mode 100644 index 000000000..2c24a6456 --- /dev/null +++ b/types/locale/types.d.ts @@ -0,0 +1,33 @@ +declare interface ILocale { + name: string + weekdays?: string[] + months?: string[] + weekStart?: number + weekdaysShort?: string[] + monthsShort?: string[] + weekdaysMin?: string[] + ordinal?: (n: number) => number | string + formats: Partial<{ + LT: string + LTS: string + L: string + LL: string + LLL: string + LLLL: string + }> + relativeTime: Partial<{ + future: string + past: string + s: string + m: string + mm: string + h: string + hh: string + d: string + dd: string + M: string + MM: string + y: string + yy: string + }> +} From aa0f210a1e3c4f6aba61c3b96f9eb445b43a33f0 Mon Sep 17 00:00:00 2001 From: iamkun Date: Mon, 9 Dec 2019 21:35:15 +0800 Subject: [PATCH 08/10] fix: Update LocaleData plugin to support dayjs().longDateFormat() (#734) fix #680 --- src/plugin/localeData/index.js | 3 ++- test/plugin/localeData.test.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/plugin/localeData/index.js b/src/plugin/localeData/index.js index c8008a22d..329090d24 100644 --- a/src/plugin/localeData/index.js +++ b/src/plugin/localeData/index.js @@ -17,7 +17,8 @@ export default (o, c, dayjs) => { // locale needed later weekdaysMin: instance => (instance ? instance.format('dd') : getShort(this, 'weekdaysMin', 'weekdays', 2)), weekdaysShort: instance => - (instance ? instance.format('ddd') : getShort(this, 'weekdaysShort', 'weekdays', 3)) + (instance ? instance.format('ddd') : getShort(this, 'weekdaysShort', 'weekdays', 3)), + longDateFormat: format => this.$locale().formats[format] } } proto.localeData = function () { diff --git a/test/plugin/localeData.test.js b/test/plugin/localeData.test.js index 151713b67..289832873 100644 --- a/test/plugin/localeData.test.js +++ b/test/plugin/localeData.test.js @@ -2,8 +2,10 @@ import MockDate from 'mockdate' import moment from 'moment' import dayjs from '../../src' import localeData from '../../src/plugin/localeData' +import localizedFormat from '../../src/plugin/localizedFormat' import '../../src/locale/zh-cn' +dayjs.extend(localizedFormat) dayjs.extend(localeData) beforeEach(() => { @@ -14,7 +16,7 @@ afterEach(() => { MockDate.reset() }) -it('instance localeData', () => { +it('Instance localeData', () => { const d = dayjs() const m = moment() const dayjsLocaleData = dayjs().localeData() @@ -28,9 +30,14 @@ it('instance localeData', () => { expect(dayjsLocaleData.weekdaysMin()).toEqual(momentLocaleData.weekdaysMin()) expect(dayjsLocaleData.weekdaysShort(d)).toBe(momentLocaleData.weekdaysShort(m)) expect(dayjsLocaleData.weekdaysShort()).toEqual(momentLocaleData.weekdaysShort()) + const longDateFormats = ['LT', 'LTS', 'L', 'LL', 'LLL', 'LLLL'] + longDateFormats.forEach((f) => { + expect(dayjsLocaleData.longDateFormat(f)).toEqual(momentLocaleData.longDateFormat(f)) + }) }) -it('global localeData', () => { + +it('Global localeData', () => { dayjs.locale('zh-cn') moment.locale('zh-cn') let dayjsLocaleData = dayjs.localeData() From 6d51435092c0c94d8e50256d3f0f058cdd15febe Mon Sep 17 00:00:00 2001 From: Munkh-Orgil Date: Wed, 18 Dec 2019 12:42:41 +0800 Subject: [PATCH 09/10] fix: Update Mongolian (mn) locale relativeTime (#753) --- src/locale/mn.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/locale/mn.js b/src/locale/mn.js index a2c863a96..3c6d8f435 100644 --- a/src/locale/mn.js +++ b/src/locale/mn.js @@ -15,6 +15,21 @@ const locale = { LL: 'YYYY оны MMMMын D', LLL: 'YYYY оны MMMMын D HH:mm', LLLL: 'dddd, YYYY оны MMMMын D HH:mm' + }, + relativeTime: { + future: '%s', + past: '%s', + s: 'саяхан', + m: 'м', + mm: '%dм', + h: '1ц', + hh: '%dц', + d: '1ө', + dd: '%dө', + M: '1с', + MM: '%dс', + y: '1ж', + yy: '%dж' } } From 78ec173fcecc1299516ab7b44f4554d431b4b2fd Mon Sep 17 00:00:00 2001 From: iamkun Date: Wed, 18 Dec 2019 14:05:53 +0800 Subject: [PATCH 10/10] fix: Fix .locale() handel unsupported locale --- src/index.js | 3 ++- test/locale.test.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 3c9fc9870..9c4b93c12 100644 --- a/src/index.js +++ b/src/index.js @@ -366,7 +366,8 @@ class Dayjs { locale(preset, object) { if (!preset) return this.$L const that = this.clone() - that.$L = parseLocale(preset, object, true) + const nextLocaleName = parseLocale(preset, object, true) + if (nextLocaleName) that.$L = nextLocaleName return that } diff --git a/test/locale.test.js b/test/locale.test.js index 1ac0aa9c2..48e1f5666 100644 --- a/test/locale.test.js +++ b/test/locale.test.js @@ -121,3 +121,12 @@ describe('Instance locale inheritance', () => { expect(dayjs.locale()).toBe(moment.locale()) }) }) + + +it('Not supported locale string fallback to previous one', () => { + const D = dayjs() + const DFormat = D.format() + const D2 = D.locale('not_supported_locale_string') + const D2Format = D2.format() + expect(DFormat).toBe(D2Format) +})