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
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 @@
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 @@
diff --git a/docs/ko/README-ko.md b/docs/ko/README-ko.md
index a80648e89..6a6ccce1d 100644
--- a/docs/ko/README-ko.md
+++ b/docs/ko/README-ko.md
@@ -5,7 +5,7 @@
@@ -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/) 웹사이트에서 볼 수 있습니다.
### 설치
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 @@
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 @@
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 @@
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
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
+
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'
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',
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: 'දිනය',
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/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/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/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())
})
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())
})
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')
diff --git a/types/index.d.ts b/types/index.d.ts
index 313f95752..5141e2335 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'
@@ -27,7 +29,7 @@ declare namespace dayjs {
export type OpUnitType = UnitType | "week" | "weeks" | 'w';
export type QUnitType = UnitType | "quarter" | "quarters" | 'Q';
-
+ export type ManipulateType = Omit