From 755fc8bb1c532eb991459f180eee81367d12016c Mon Sep 17 00:00:00 2001 From: henry <48340699+imwh0im@users.noreply.github.com> Date: Wed, 7 Jul 2021 11:28:47 +0900 Subject: [PATCH 01/14] fix: update plugin advancedFormat `isValid` validation (#1566) --- src/plugin/advancedFormat/index.js | 5 +++++ test/plugin/advancedFormat.test.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/plugin/advancedFormat/index.js b/src/plugin/advancedFormat/index.js index 6ebd3f43b..a78296f7a 100644 --- a/src/plugin/advancedFormat/index.js +++ b/src/plugin/advancedFormat/index.js @@ -11,6 +11,11 @@ export default (o, c, d) => { // locale needed later // extend en locale here proto.format = function (formatStr) { const locale = this.$locale() + + if (!this.isValid()) { + return oldFormat.bind(this)(formatStr) + } + const utils = this.$utils() const str = formatStr || FORMAT_DEFAULT const result = str.replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g, (match) => { diff --git a/test/plugin/advancedFormat.test.js b/test/plugin/advancedFormat.test.js index d9512e086..955f94032 100644 --- a/test/plugin/advancedFormat.test.js +++ b/test/plugin/advancedFormat.test.js @@ -24,6 +24,10 @@ afterEach(() => { MockDate.reset() }) +it('Format of invalid date', () => { + expect(dayjs(null).format('z').toLowerCase()).toEqual(moment(null).format('z').toLowerCase()) +}) + it('Format empty string', () => { expect(dayjs().format()).toBe(moment().format()) }) From 08adda54edbcca38601f57841921d0f87f84e49e Mon Sep 17 00:00:00 2001 From: iamkun Date: Wed, 7 Jul 2021 15:20:07 +0800 Subject: [PATCH 02/14] fix: update customParseFormat plugin strict x X parsing (#1571) --- src/plugin/customParseFormat/index.js | 5 ++++- test/plugin/customParseFormat.test.js | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index 73e48eb91..fc3b788f4 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -232,7 +232,10 @@ export default (o, C, d) => { this.$d = parseFormattedInput(date, format, utc) this.init() if (pl && pl !== true) this.$L = this.locale(pl).$L - if (isStrict && date !== this.format(format)) { + // use != to treat + // input number 1410715640579 and format string '1410715640579' equal + // eslint-disable-next-line eqeqeq + if (isStrict && date != this.format(format)) { this.$d = new Date('') } // reset global locale to make parallel unit test diff --git a/test/plugin/customParseFormat.test.js b/test/plugin/customParseFormat.test.js index 97fe8fb73..3b4e5f9cb 100644 --- a/test/plugin/customParseFormat.test.js +++ b/test/plugin/customParseFormat.test.js @@ -5,6 +5,7 @@ import '../../src/locale/ru' import uk from '../../src/locale/uk' import '../../src/locale/zh-cn' import customParseFormat from '../../src/plugin/customParseFormat' +import advancedFormat from '../../src/plugin/advancedFormat' import localizedFormats from '../../src/plugin/localizedFormat' dayjs.extend(customParseFormat) @@ -376,4 +377,8 @@ it('parse X x', () => { const input2 = '1410715640579' const format2 = 'x' expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf()) + + // x X starct parse requires advancedFormat plugin + dayjs.extend(advancedFormat) + expect(dayjs(input2, format2, true).valueOf()).toBe(moment(input2, format2, true).valueOf()) }) From 5a79cc6408e825d9e123629eb44fc19c996d7751 Mon Sep 17 00:00:00 2001 From: Mohammad ali Ali panah <58308349+always-maap@users.noreply.github.com> Date: Mon, 12 Jul 2021 08:16:49 +0430 Subject: [PATCH 03/14] fix: add format object type to type file (#1572) --- types/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 313f95752..d5ce14a2f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -15,7 +15,9 @@ declare namespace dayjs { export type ConfigType = ConfigTypeMap[keyof ConfigTypeMap] - export type OptionType = { locale?: string, format?: string, utc?: boolean } | string | string[] + export interface FormatObject { locale?: string, format?: string, utc?: boolean } + + export type OptionType = FormatObject | string | string[] export type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms' From 63de2a8b7dcd7e68c132c85d88572d4c9d296907 Mon Sep 17 00:00:00 2001 From: Aikatsui <63988538+Aikatsui@users.noreply.github.com> Date: Tue, 27 Jul 2021 14:55:51 +0700 Subject: [PATCH 04/14] fix: update Sinhalese [si] locale month name (#1475) --- src/locale/si.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/locale/si.js b/src/locale/si.js index fcd685120..f76b7927f 100644 --- a/src/locale/si.js +++ b/src/locale/si.js @@ -4,9 +4,9 @@ import dayjs from 'dayjs' const locale = { name: 'si', weekdays: 'ඉරිදා_සඳුදා_අඟහරුවාදා_බදාදා_බ්‍රහස්පතින්දා_සිකුරාදා_සෙනසුරාදා'.split('_'), - months: 'ජනවාරි_පෙබරවාරි_මාර්තු_අප්‍රේල්_මැයි_ජූනි_ජූලි_අගෝස්තු_සැප්තැම්බර්_ඔක්තෝබර්_නොවැම්බර්_දෙසැම්බර්'.split('_'), + months: 'දුරුතු_නවම්_මැදින්_බක්_වෙසක්_පොසොන්_ඇසළ_නිකිණි_බිනර_වප්_ඉල්_උඳුවප්'.split('_'), weekdaysShort: 'ඉරි_සඳු_අඟ_බදා_බ්‍රහ_සිකු_සෙන'.split('_'), - monthsShort: 'ජන_පෙබ_මාර්_අප්_මැයි_ජූනි_ජූලි_අගෝ_සැප්_ඔක්_නොවැ_දෙසැ'.split('_'), + monthsShort: 'දුරු_නව_මැදි_බක්_වෙස_පොසො_ඇස_නිකි_බින_වප්_ඉල්_උඳු'.split('_'), weekdaysMin: 'ඉ_ස_අ_බ_බ්‍ර_සි_සෙ'.split('_'), ordinal: n => n, formats: { @@ -21,8 +21,8 @@ const locale = { future: '%sකින්', past: '%sකට පෙර', s: 'තත්පර කිහිපය', - m: 'මිනිත්තුව', - mm: 'මිනිත්තු %d', + m: 'විනාඩිය', + mm: 'විනාඩි %d', h: 'පැය', hh: 'පැය %d', d: 'දිනය', From 16869621b1a42563064dbf87f80c1ebfd74c1188 Mon Sep 17 00:00:00 2001 From: susiwen8 Date: Sat, 31 Jul 2021 11:22:43 +0800 Subject: [PATCH 05/14] fix: narrow type for `add` and `subtract` (#1576) --- types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index d5ce14a2f..5141e2335 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -29,7 +29,7 @@ declare namespace dayjs { export type OpUnitType = UnitType | "week" | "weeks" | 'w'; export type QUnitType = UnitType | "quarter" | "quarters" | 'Q'; - + export type ManipulateType = Omit; class Dayjs { constructor (config?: ConfigType) /** @@ -237,7 +237,7 @@ declare namespace dayjs { * * Docs: https://day.js.org/docs/en/manipulate/add */ - add(value: number, unit?: OpUnitType): Dayjs + add(value: number, unit?: ManipulateType): Dayjs /** * Returns a cloned Day.js object with a specified amount of time subtracted. * ``` @@ -247,7 +247,7 @@ declare namespace dayjs { * * Docs: https://day.js.org/docs/en/manipulate/subtract */ - subtract(value: number, unit?: OpUnitType): Dayjs + subtract(value: number, unit?: ManipulateType): Dayjs /** * Returns a cloned Day.js object and set it to the start of a unit of time. * ``` From e2feb6bfa555fe3412934cbf18ac93f51ff34d99 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 4 Aug 2021 04:23:13 -0300 Subject: [PATCH 06/14] fx: Fix esm duration typings. (#1589) --- types/plugin/duration.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/plugin/duration.d.ts b/types/plugin/duration.d.ts index a7e733fe2..9675a80b8 100644 --- a/types/plugin/duration.d.ts +++ b/types/plugin/duration.d.ts @@ -1,5 +1,5 @@ import { PluginFunc } from 'dayjs' -import { OpUnitType, UnitTypeLongPlural } from "../index"; +import { OpUnitType, UnitTypeLongPlural } from 'dayjs'; declare const plugin: PluginFunc export as namespace plugin; From f68e4b1a29fc33542f74cde10ec6d9fb045ca37e Mon Sep 17 00:00:00 2001 From: Nikita Orobenko <62012180+NikiO-INO@users.noreply.github.com> Date: Tue, 17 Aug 2021 07:57:48 +0300 Subject: [PATCH 07/14] fix: update utcOffset plugin type file (#1604) --- types/plugin/utc.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/plugin/utc.d.ts b/types/plugin/utc.d.ts index 2cdd7525c..544ea4e70 100644 --- a/types/plugin/utc.d.ts +++ b/types/plugin/utc.d.ts @@ -12,7 +12,7 @@ declare module 'dayjs' { isUTC(): boolean - utcOffset(offset: number, keepLocalTime?: boolean): Dayjs + utcOffset(offset: number | string, keepLocalTime?: boolean): Dayjs } export function utc(config?: ConfigType, format?: string, strict?: boolean): Dayjs From 08fe8a9cf946b5b59ab2b167878594e4a580e63e Mon Sep 17 00:00:00 2001 From: cog25 Date: Fri, 10 Sep 2021 17:54:43 +0900 Subject: [PATCH 08/14] chore: Update README-ko.md (#1630) --- docs/ko/README-ko.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ko/README-ko.md b/docs/ko/README-ko.md index a80648e89..9c450c04b 100644 --- a/docs/ko/README-ko.md +++ b/docs/ko/README-ko.md @@ -42,9 +42,9 @@ dayjs() ## 시작해볼까요! -### Documentation +### 문서 -You can find for more details, API, and other docs on [day.js.org](https://day.js.org/) website. +더 많은 세부 사항과 API, 그리고 다른 문서를 [day.js.org](https://day.js.org/) 웹사이트에서 볼 수 있습니다. ### 설치 From f858260790250880fc74ab7108073435f534d7f1 Mon Sep 17 00:00:00 2001 From: Aex Date: Fri, 10 Sep 2021 16:55:52 +0800 Subject: [PATCH 09/14] chore: Use secure url for badgesize (#1602) --- README.md | 2 +- docs/es-es/README-es-es.md | 2 +- docs/ja/README-ja.md | 2 +- docs/ko/README-ko.md | 2 +- docs/pt-br/README-pt-br.md | 2 +- docs/ru/README-ru.md | 2 +- docs/zh-cn/README.zh-CN.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9e665b782..ef306253c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/R

Fast 2kB alternative to Moment.js with the same modern API

Gzip Size NPM Version diff --git a/docs/es-es/README-es-es.md b/docs/es-es/README-es-es.md index a08c3d868..4e536343c 100644 --- a/docs/es-es/README-es-es.md +++ b/docs/es-es/README-es-es.md @@ -5,7 +5,7 @@

Gzip Size NPM Version diff --git a/docs/ja/README-ja.md b/docs/ja/README-ja.md index 329d34c31..1cc8ca36e 100644 --- a/docs/ja/README-ja.md +++ b/docs/ja/README-ja.md @@ -5,7 +5,7 @@

Gzip Size NPM Version diff --git a/docs/ko/README-ko.md b/docs/ko/README-ko.md index 9c450c04b..6a6ccce1d 100644 --- a/docs/ko/README-ko.md +++ b/docs/ko/README-ko.md @@ -5,7 +5,7 @@

Gzip Size NPM Version diff --git a/docs/pt-br/README-pt-br.md b/docs/pt-br/README-pt-br.md index 7123dd2eb..275928dd4 100644 --- a/docs/pt-br/README-pt-br.md +++ b/docs/pt-br/README-pt-br.md @@ -5,7 +5,7 @@

Gzip Size NPM Version diff --git a/docs/ru/README-ru.md b/docs/ru/README-ru.md index a6b5f1229..55f22c852 100644 --- a/docs/ru/README-ru.md +++ b/docs/ru/README-ru.md @@ -5,7 +5,7 @@

Gzip Size NPM Version diff --git a/docs/zh-cn/README.zh-CN.md b/docs/zh-cn/README.zh-CN.md index aecc858b4..af94085c2 100644 --- a/docs/zh-cn/README.zh-CN.md +++ b/docs/zh-cn/README.zh-CN.md @@ -5,7 +5,7 @@

Gzip Size NPM Version From 7a8467c0b7d59821f7e19d4a6973bcda8e4c19b1 Mon Sep 17 00:00:00 2001 From: Torgny Walin Date: Fri, 10 Sep 2021 10:57:10 +0200 Subject: [PATCH 10/14] =?UTF-8?q?fix:=20Update=20Norwegian=20Bokm=C3=A5l?= =?UTF-8?q?=20[nb]=20local=20yearStart=204=20(#1608)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/locale/nb.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/locale/nb.js b/src/locale/nb.js index e9614dcf5..80be733cc 100644 --- a/src/locale/nb.js +++ b/src/locale/nb.js @@ -10,6 +10,7 @@ const locale = { monthsShort: 'jan._feb._mars_april_mai_juni_juli_aug._sep._okt._nov._des.'.split('_'), ordinal: n => `${n}.`, weekStart: 1, + yearStart: 4, formats: { LT: 'HH:mm', LTS: 'HH:mm:ss', From 255dc54d9295de135a9037ce6ca13cae4bfd2cfb Mon Sep 17 00:00:00 2001 From: Matas Seimys Date: Fri, 10 Sep 2021 11:58:49 +0300 Subject: [PATCH 11/14] fix: update Lithuanian [lt] locale spelling for single month (#1609) --- src/locale/lt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale/lt.js b/src/locale/lt.js index c846e1177..76f849125 100644 --- a/src/locale/lt.js +++ b/src/locale/lt.js @@ -34,7 +34,7 @@ const locale = { hh: '%d valandas', d: 'dieną', dd: '%d dienas', - M: 'menesį', + M: 'mėnesį', MM: '%d mėnesius', y: 'metus', yy: '%d metus' From 252585b4b2bd59508150e21bb994908a9d78f9b0 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Fri, 10 Sep 2021 11:03:15 +0200 Subject: [PATCH 12/14] fix: duration plugin when parsing duration from ISO string, set missing components to 0 instead of NaN (#1611) --- src/plugin/duration/index.js | 2 +- test/plugin/duration.test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugin/duration/index.js b/src/plugin/duration/index.js index 4e894647a..10ebb4ca2 100644 --- a/src/plugin/duration/index.js +++ b/src/plugin/duration/index.js @@ -84,7 +84,7 @@ class Duration { const d = input.match(durationRegex) if (d) { const properties = d.slice(2) - const numberD = properties.map(value => Number(value)); + const numberD = properties.map(value => (value != null ? Number(value) : 0)); [ this.$d.years, this.$d.months, diff --git a/test/plugin/duration.test.js b/test/plugin/duration.test.js index cca1a828e..2e804691c 100644 --- a/test/plugin/duration.test.js +++ b/test/plugin/duration.test.js @@ -76,6 +76,9 @@ describe('Parse ISO string', () => { it('Part ISO string', () => { expect(dayjs.duration('PT2777H46M40S').toISOString()).toBe('PT2777H46M40S') }) + it('Formatting missing components', () => { + expect(dayjs.duration('PT1H').format('YYYY-MM-DDTHH:mm:ss')).toBe('0000-00-00T01:00:00') + }) it('ISO string with week', () => { const d = dayjs.duration('P2M3W4D') expect(d.toISOString()).toBe('P2M25D') From 3393f2ad55346d55902683a2e31c6f253d96c8c2 Mon Sep 17 00:00:00 2001 From: Roberto Orozco Date: Fri, 10 Sep 2021 04:07:03 -0500 Subject: [PATCH 13/14] fix: Add Spanish (Mexico) [es-mx] locale (#1614) --- src/locale/es-mx.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/locale/es-mx.js diff --git a/src/locale/es-mx.js b/src/locale/es-mx.js new file mode 100644 index 000000000..e3ad88804 --- /dev/null +++ b/src/locale/es-mx.js @@ -0,0 +1,40 @@ +// Spanish (Mexico) [es-mx] +import dayjs from 'dayjs' + +const locale = { + name: 'es-mx', + weekdays: 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'), + weekdaysShort: 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'), + weekdaysMin: 'do_lu_ma_mi_ju_vi_sá'.split('_'), + months: 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'), + monthsShort: 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'), + relativeTime: { + future: 'en %s', + past: 'hace %s', + s: 'unos segundos', + m: 'un minuto', + mm: '%d minutos', + h: 'una hora', + hh: '%d horas', + d: 'un día', + dd: '%d días', + M: 'un mes', + MM: '%d meses', + y: 'un año', + yy: '%d años' + }, + ordinal: n => `${n}º`, + formats: { + LT: 'H:mm', + LTS: 'H:mm:ss', + L: 'DD/MM/YYYY', + LL: 'D [de] MMMM [de] YYYY', + LLL: 'D [de] MMMM [de] YYYY H:mm', + LLLL: 'dddd, D [de] MMMM [de] YYYY H:mm' + } +} + +dayjs.locale(locale, null, true) + +export default locale + From b5a1391011b247d08863d291542db5937b23b427 Mon Sep 17 00:00:00 2001 From: Mohammed Salman Date: Fri, 10 Sep 2021 12:13:15 +0300 Subject: [PATCH 14/14] fix: Add Arabic (Iraq) [ar-iq] locale (#1627) * Add iraqi arabic locale * Update ar-iq.js Co-authored-by: iamkun --- src/locale/ar-iq.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/locale/ar-iq.js diff --git a/src/locale/ar-iq.js b/src/locale/ar-iq.js new file mode 100644 index 000000000..1040db80d --- /dev/null +++ b/src/locale/ar-iq.js @@ -0,0 +1,41 @@ +// Arabic (Iraq) [ar-iq] +import dayjs from 'dayjs' + +const locale = { + name: 'ar-iq', + weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'), + months: 'كانون الثاني_شباط_آذار_نيسان_أيار_حزيران_تموز_آب_أيلول_تشرين الأول_ تشرين الثاني_كانون الأول'.split('_'), + weekStart: 1, + weekdaysShort: 'أحد_إثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'.split('_'), + monthsShort: 'كانون الثاني_شباط_آذار_نيسان_أيار_حزيران_تموز_آب_أيلول_تشرين الأول_ تشرين الثاني_كانون الأول'.split('_'), + weekdaysMin: 'ح_ن_ث_ر_خ_ج_س'.split('_'), + ordinal: n => n, + formats: { + LT: 'HH:mm', + LTS: 'HH:mm:ss', + L: 'DD/MM/YYYY', + LL: 'D MMMM YYYY', + LLL: 'D MMMM YYYY HH:mm', + LLLL: 'dddd D MMMM YYYY HH:mm' + }, + meridiem: hour => (hour > 12 ? 'ص' : 'م'), + relativeTime: { + future: 'في %s', + past: 'منذ %s', + s: 'ثوان', + m: 'دقيقة', + mm: '%d دقائق', + h: 'ساعة', + hh: '%d ساعات', + d: 'يوم', + dd: '%d أيام', + M: 'شهر', + MM: '%d أشهر', + y: 'سنة', + yy: '%d سنوات' + } +} + +dayjs.locale(locale, null, true) + +export default locale