From 890a17a8d8ddd43c7c8b806e3afc7b27f3288d27 Mon Sep 17 00:00:00 2001
From: Creed Haymond
Date: Tue, 4 Jul 2023 22:25:30 -0600
Subject: [PATCH 01/15] fix: round durations to millisecond precision for ISO
string (#2367)
---
src/plugin/duration/index.js | 2 +-
test/plugin/duration.test.js | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/plugin/duration/index.js b/src/plugin/duration/index.js
index 26bc75e34..d7adf7517 100644
--- a/src/plugin/duration/index.js
+++ b/src/plugin/duration/index.js
@@ -139,7 +139,7 @@ class Duration {
let seconds = this.$d.seconds || 0
if (this.$d.milliseconds) {
- seconds += this.$d.milliseconds / 1000
+ seconds += Math.round(this.$d.milliseconds) / 1000
}
const S = getNumberUnitFormat(seconds, 'S')
diff --git a/test/plugin/duration.test.js b/test/plugin/duration.test.js
index 4a4753931..eec20b1e3 100644
--- a/test/plugin/duration.test.js
+++ b/test/plugin/duration.test.js
@@ -70,6 +70,13 @@ describe('Creating', () => {
it('convert to milliseconds', () => {
expect(+dayjs.duration(100)).toBe(100)
})
+ it('handles rounding to millisecond precision', () => {
+ expect(dayjs.duration(2 / 3).toISOString()).toBe('PT0.001S')
+ })
+ it('should handle round with millisecond precision when negative', () => {
+ expect(dayjs.duration(1000.5).toISOString()).toBe('PT1.001S')
+ expect(dayjs.duration(-1000.5).toISOString()).toBe('-PT1S')
+ })
})
describe('Parse ISO string', () => {
From f0a0b546b074b3b511c2319a1ce83d412894b91f Mon Sep 17 00:00:00 2001
From: Sanjay Kumar Nishad
Date: Sun, 9 Jul 2023 17:17:57 +0530
Subject: [PATCH 02/15] fix: duration plugin - MILLISECONDS_A_MONTH const
calculation (#2362)
---
src/plugin/duration/index.js | 2 +-
test/plugin/duration.test.js | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/plugin/duration/index.js b/src/plugin/duration/index.js
index d7adf7517..000047065 100644
--- a/src/plugin/duration/index.js
+++ b/src/plugin/duration/index.js
@@ -8,7 +8,7 @@ import {
} from '../../constant'
const MILLISECONDS_A_YEAR = MILLISECONDS_A_DAY * 365
-const MILLISECONDS_A_MONTH = MILLISECONDS_A_DAY * 30
+const MILLISECONDS_A_MONTH = MILLISECONDS_A_YEAR / 12
const durationRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/
diff --git a/test/plugin/duration.test.js b/test/plugin/duration.test.js
index eec20b1e3..7c6c6998a 100644
--- a/test/plugin/duration.test.js
+++ b/test/plugin/duration.test.js
@@ -92,8 +92,9 @@ describe('Parse ISO string', () => {
it('ISO string with week', () => {
const d = dayjs.duration('P2M3W4D')
expect(d.toISOString()).toBe('P2M25D')
- expect(d.asDays()).toBe(85) // moment 85, count 2M as 61 days
- expect(d.asWeeks()).toBe(12.142857142857142) // moment 12.285714285714286
+ expect(d.asDays()).toBe(85.83333333333333) // moment 86, count 2M as 61 days
+ expect(d.asWeeks()).toBe(12.261904761904763) // moment 12.285714285714286
+ expect(d.asMonths()).toBe(2.8219178082191783) // moment 2.8213721020965523
})
it('Invalid ISO string', () => {
expect(dayjs.duration('Invalid').toISOString()).toBe('P0D')
From 061aa7ed6c31696974665fc9b11a74d30841ebed Mon Sep 17 00:00:00 2001
From: iamkun
Date: Sat, 15 Jul 2023 10:51:03 +0800
Subject: [PATCH 03/15] fix: duration plugin getter get result 0 instead of
undefined (#2369)
---
src/plugin/duration/index.js | 2 +-
test/plugin/duration.test.js | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/plugin/duration/index.js b/src/plugin/duration/index.js
index 000047065..70d49296c 100644
--- a/src/plugin/duration/index.js
+++ b/src/plugin/duration/index.js
@@ -198,7 +198,7 @@ class Duration {
} else {
base = this.$d[pUnit]
}
- return base === 0 ? 0 : base // a === 0 will be true on both 0 and -0
+ return base || 0 // a === 0 will be true on both 0 and -0
}
add(input, unit, isSubtract) {
diff --git a/test/plugin/duration.test.js b/test/plugin/duration.test.js
index 7c6c6998a..f2c44156d 100644
--- a/test/plugin/duration.test.js
+++ b/test/plugin/duration.test.js
@@ -186,6 +186,12 @@ describe('Add', () => {
expect(a.add({ days: 5 }).days()).toBe(6)
})
+describe('Add to a dayjs()', () => {
+ const a = dayjs()
+ const b = dayjs.duration({ hours: 7, minutes: 10 })
+ expect(a.add(b)).toEqual(a.add(7, 'hours').add(10, 'minutes'))
+})
+
test('Add duration', () => {
const a = dayjs('2020-10-01')
const days = dayjs.duration(2, 'days')
From 8c7de64276ad4b1f0fb792d8b7a24eabd6de199c Mon Sep 17 00:00:00 2001
From: Ikko Eltociear Ashimine
Date: Sat, 22 Jul 2023 01:04:00 +0900
Subject: [PATCH 04/15] docs: update README-ja.md (#2378)
---
docs/ja/README-ja.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/ja/README-ja.md b/docs/ja/README-ja.md
index a708a03bb..32f466305 100644
--- a/docs/ja/README-ja.md
+++ b/docs/ja/README-ja.md
@@ -1,4 +1,4 @@
-日本語 | [English](../../README.md) | [简体中文](../zh-cn/README.zh-CN.md) | [Português Brasileiro](../pt-br/README-pt-br.md) | [한국어](../ko/README-ko.md) | [Español (España)](../es-es/README-es-es.md) | [Русский](../ru/README-ru.md)| [עברית](./docs/he/README-he.md)
+日本語 | [English](../../README.md) | [简体中文](../zh-cn/README.zh-CN.md) | [Português Brasileiro](../pt-br/README-pt-br.md) | [한국어](../ko/README-ko.md) | [Español (España)](../es-es/README-es-es.md) | [Русский](../ru/README-ru.md)| [עברית](../he/README-he.md)
Date: Thu, 27 Jul 2023 14:08:45 +0800
Subject: [PATCH 05/15] fix: fix isDayjs check logic (#2383)
---
src/index.js | 8 ++++++--
test/constructor.test.js | 8 ++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/index.js b/src/index.js
index 16c2e351a..d26a401a6 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,7 +6,10 @@ let L = 'en' // global locale
const Ls = {} // global loaded locale
Ls[L] = en
-const isDayjs = d => d instanceof Dayjs // eslint-disable-line no-use-before-define
+const IS_DAYJS = '$isDayjsObject'
+
+// eslint-disable-next-line no-use-before-define
+const isDayjs = d => d instanceof Dayjs || !!(d && d[IS_DAYJS])
const parseLocale = (preset, object, isLocal) => {
let l
@@ -72,7 +75,7 @@ const parseDate = (cfg) => {
|| 1, d[4] || 0, d[5] || 0, d[6] || 0, ms))
}
return new Date(d[1], m, d[3]
- || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)
+ || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms)
}
}
@@ -83,6 +86,7 @@ class Dayjs {
constructor(cfg) {
this.$L = parseLocale(cfg.locale, null, true)
this.parse(cfg) // for plugin
+ this[IS_DAYJS] = true
}
parse(cfg) {
diff --git a/test/constructor.test.js b/test/constructor.test.js
index b14b2fec4..66cdbfc68 100644
--- a/test/constructor.test.js
+++ b/test/constructor.test.js
@@ -13,6 +13,14 @@ it('supports instanceof dayjs', () => {
expect(dayjs() instanceof dayjs).toBeTruthy()
})
+it('$isDayjsObject', () => {
+ const mockOtherVersionDayjsObj = {
+ $isDayjsObject: true
+ }
+ expect(dayjs.isDayjs(mockOtherVersionDayjsObj)).toBeTruthy()
+})
+
it('does not break isDayjs', () => {
expect(dayjs.isDayjs(dayjs())).toBeTruthy()
+ expect(dayjs.isDayjs(new Date())).toBeFalsy()
})
From a9d7d0398d22ebd4bfc3812ca0134a97606d54d9 Mon Sep 17 00:00:00 2001
From: Creed Haymond
Date: Thu, 27 Jul 2023 00:09:29 -0600
Subject: [PATCH 06/15] fix: sub-second precisions need to be rounded at the
seconds field to avoid adding floats (#2377)
---
src/plugin/duration/index.js | 3 ++-
test/plugin/duration.test.js | 9 +++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/plugin/duration/index.js b/src/plugin/duration/index.js
index 70d49296c..e2060c344 100644
--- a/src/plugin/duration/index.js
+++ b/src/plugin/duration/index.js
@@ -139,7 +139,8 @@ class Duration {
let seconds = this.$d.seconds || 0
if (this.$d.milliseconds) {
- seconds += Math.round(this.$d.milliseconds) / 1000
+ seconds += this.$d.milliseconds / 1000
+ seconds = Math.round(seconds * 1000) / 1000
}
const S = getNumberUnitFormat(seconds, 'S')
diff --git a/test/plugin/duration.test.js b/test/plugin/duration.test.js
index f2c44156d..3e726af91 100644
--- a/test/plugin/duration.test.js
+++ b/test/plugin/duration.test.js
@@ -77,6 +77,15 @@ describe('Creating', () => {
expect(dayjs.duration(1000.5).toISOString()).toBe('PT1.001S')
expect(dayjs.duration(-1000.5).toISOString()).toBe('-PT1S')
})
+ it('should handle floating point rounding errors', () => {
+ // An example of this is when adding 2 to 0.812 seconds, which is how
+ // the seconds component is calculated in .toISOString().
+ // > 2 + 0.812
+ // 2.8120000000000003
+ expect(dayjs.duration(-2812).toISOString()).toBe('-PT2.812S') // was -PT2.8120000000000003S
+ expect(dayjs.duration(3121632.27382247).toISOString()).toBe('PT52M1.632S') // was PT52M1.6320000000000001S
+ expect(dayjs.duration(7647826.525774224).toISOString()).toBe('PT2H7M27.827S') // was PT2H7M27.826999999999998S
+ })
})
describe('Parse ISO string', () => {
From 361be5c7c628614ee833d710acbe154a598b904d Mon Sep 17 00:00:00 2001
From: Aland Abdullah <32212842+alandio@users.noreply.github.com>
Date: Tue, 19 Sep 2023 14:36:25 +0300
Subject: [PATCH 07/15] fix(locale): add meridiem in `ar` locale (#2418)
---
src/locale/ar.js | 2 ++
test/locale/ar.test.js | 10 ++++++++++
2 files changed, 12 insertions(+)
diff --git a/src/locale/ar.js b/src/locale/ar.js
index a7025c442..f418379c8 100644
--- a/src/locale/ar.js
+++ b/src/locale/ar.js
@@ -2,6 +2,7 @@
import dayjs from 'dayjs'
const months = 'يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'.split('_')
+
const symbolMap = {
1: '١',
2: '٢',
@@ -36,6 +37,7 @@ const locale = {
months,
monthsShort: months,
weekStart: 6,
+ meridiem: hour => (hour > 12 ? 'م' : 'ص'),
relativeTime: {
future: 'بعد %s',
past: 'منذ %s',
diff --git a/test/locale/ar.test.js b/test/locale/ar.test.js
index 3f9f60f0c..2b5a57d29 100644
--- a/test/locale/ar.test.js
+++ b/test/locale/ar.test.js
@@ -50,3 +50,13 @@ it('RelativeTime: Time from X gets formatted', () => {
.toBe(t[2])
})
})
+
+it('Format meridiem with locale function', () => {
+ for (let i = 0; i <= 23; i += 1) {
+ const hour = dayjs()
+ .startOf('day')
+ .add(i, 'hour')
+ const meridiem = i > 12 ? 'م' : 'ص'
+ expect(hour.locale('ar').format('A')).toBe(`${meridiem}`)
+ }
+})
From b776b225479feb376b90e711dae9625180e40124 Mon Sep 17 00:00:00 2001
From: JIMIN PARK <103014298+keepinblazing@users.noreply.github.com>
Date: Tue, 19 Sep 2023 20:38:54 +0900
Subject: [PATCH 08/15] docs: corrected incorrect Korean translations (#2414)
---
docs/ko/README-ko.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/docs/ko/README-ko.md b/docs/ko/README-ko.md
index 4389cc3db..cb1f77ab9 100644
--- a/docs/ko/README-ko.md
+++ b/docs/ko/README-ko.md
@@ -23,7 +23,7 @@
-> Day.js는 Moment.js와 호환되는 대부분의 API를 사용하며, 최신 브라우저에서 날짜와 시간에 대한 구문 분석, 유효성 검사, 조작, 출력하는 경량 JavaScript 라이브러리입니다. Moment.js를 사용하고 있다면, Day.js는 껌입니다.
+> Day.js는 대부분의 API가 Moment.js와 호환되며 최신 브라우저에서 날짜와 시간에 대한 구문 분석, 유효성 검사, 조작, 출력을 간편하게 처리하는 경량 JavaScript 라이브러리 입니다. Moment.js를 사용해본 경험이 있다면, Day.js도 쉽게 사용하실 수 있습니다.
```js
dayjs()
@@ -46,7 +46,7 @@ dayjs()
### 문서
-더 많은 세부 사항과 API, 그리고 다른 문서를 [day.js.org](https://day.js.org/) 웹사이트에서 볼 수 있습니다.
+더 많은 세부 사항과 API 및 다른 문서는 [day.js.org](https://day.js.org/) 웹사이트에서 확인하실 수 있습니다.
### 설치
@@ -58,7 +58,7 @@ npm install dayjs --save
### API
-Day.js API를 사용해서 날짜와 시간에 대한 구문 분석, 유효성 검사, 조작, 출력을 쉽게 할 수 있습니다.
+Day.js API를 사용하여 날짜와 시간의 구문 분석, 검증, 조작, 출력을 간편하게 처리할 수 있습니다.
```javascript
dayjs('2018-08-08') // parse
@@ -78,9 +78,9 @@ dayjs().isBefore(dayjs()) // query
### I18n
-Day.js는 국제화에 대해 많은 지원을 합니다.
+Day.js는 국제화에 대한 많은 지원을 제공하고 있습니다.
-그러나 그것을 사용하지 않는다면, 그 누구도 당신의 빌드에 포함되지 않습니다.
+하지만 이 기능을 사용하지 않는 경우, 빌드에 포함되지 않습니다.
```javascript
import 'dayjs/locale/es' // load on demand
@@ -96,7 +96,7 @@ dayjs('2018-05-05')
### Plugin
-플러그인은 기능을 확장하거나 새로운 기능을 추가하기 위해 Day.js에 추가할 수 있는 독립적인 모듈입니다.
+플러그인은 Day.js의 기능을 확장하거나 새로운 기능을 도입하기 위한 독립적인 모듈입니다.
```javascript
import advancedFormat from 'dayjs/plugin/advancedFormat' // load on demand
From dd55ee2aadd1009242235e47d558bbf028827896 Mon Sep 17 00:00:00 2001
From: Sangho Jin
Date: Tue, 19 Sep 2023 20:40:11 +0900
Subject: [PATCH 09/15] fix: Add Korean Day of Month with ordinal (#2395)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* add '일' suffix to 'Do' format
---
src/locale/ko.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/locale/ko.js b/src/locale/ko.js
index 8a8e8ea9b..7053e83f3 100644
--- a/src/locale/ko.js
+++ b/src/locale/ko.js
@@ -8,7 +8,7 @@ const locale = {
weekdaysMin: '일_월_화_수_목_금_토'.split('_'),
months: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
monthsShort: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
- ordinal: n => n,
+ ordinal: n => `${n}일`,
formats: {
LT: 'A h:mm',
LTS: 'A h:mm:ss',
From 5470a15e437fac803797363063b24f3ba3bd5299 Mon Sep 17 00:00:00 2001
From: alesf
Date: Tue, 19 Sep 2023 13:41:20 +0200
Subject: [PATCH 10/15] fix: Update Slovenian locale for relative time (#2396)
Slovenian translation update so it handles dual and some plural edge cases.
---
src/locale/sl.js | 91 ++++++++++++++++++++++++++++++++++++------
test/locale/sl.test.js | 82 +++++++++++++++++++++++++++++++++++++
2 files changed, 160 insertions(+), 13 deletions(-)
create mode 100644 test/locale/sl.test.js
diff --git a/src/locale/sl.js b/src/locale/sl.js
index f09e3bfce..1e0e4f885 100644
--- a/src/locale/sl.js
+++ b/src/locale/sl.js
@@ -1,6 +1,71 @@
// Slovenian [sl]
import dayjs from 'dayjs'
+function dual(n) {
+ return (n % 100) == 2 // eslint-disable-line
+}
+
+function threeFour(n) {
+ return (n % 100) == 3 || (n % 100) == 4 // eslint-disable-line
+}
+
+/* eslint-disable */
+function translate(number, withoutSuffix, key, isFuture) {
+ const result = `${number} `
+ switch (key) {
+ case 's': // a few seconds / in a few seconds / a few seconds ago
+ return (withoutSuffix || isFuture) ? 'nekaj sekund' : 'nekaj sekundami'
+ case 'm': // a minute / in a minute / a minute ago
+ return withoutSuffix ? 'ena minuta' : 'eno minuto'
+ case 'mm': // 9 minutes / in 9 minutes / 9 minutes ago
+ if (dual(number)) {
+ return result + ((withoutSuffix || isFuture) ? 'minuti' : 'minutama')
+ }
+ if (threeFour(number)) {
+ return result + ((withoutSuffix || isFuture) ? 'minute' : 'minutami')
+ }
+ return result + ((withoutSuffix || isFuture) ? 'minut' : 'minutami')
+ case 'h': // an hour / in an hour / an hour ago
+ return withoutSuffix ? 'ena ura' : (isFuture ? 'eno uro' : 'eno uro')
+ case 'hh': // 9 hours / in 9 hours / 9 hours ago
+ if (dual(number)) {
+ return result + ((withoutSuffix || isFuture) ? 'uri' : 'urama')
+ }
+ if (threeFour(number)) {
+ return result + ((withoutSuffix || isFuture) ? 'ure' : 'urami')
+ }
+ return result + ((withoutSuffix || isFuture) ? 'ur' : 'urami')
+ case 'd': // a day / in a day / a day ago
+ return (withoutSuffix || isFuture) ? 'en dan' : 'enim dnem'
+ case 'dd': // 9 days / in 9 days / 9 days ago
+ if (dual(number)) {
+ return result + ((withoutSuffix || isFuture) ? 'dneva' : 'dnevoma')
+ }
+ return result + ((withoutSuffix || isFuture) ? 'dni' : 'dnevi')
+ case 'M': // a month / in a month / a month ago
+ return (withoutSuffix || isFuture) ? 'en mesec' : 'enim mesecem'
+ case 'MM': // 9 months / in 9 months / 9 months ago
+ if (dual(number)) { // 2 minutes / in 2 minutes
+ return result + ((withoutSuffix || isFuture) ? 'meseca' : 'mesecema')
+ }
+ if (threeFour(number)) {
+ return result + ((withoutSuffix || isFuture) ? 'mesece' : 'meseci')
+ }
+ return result + ((withoutSuffix || isFuture) ? 'mesecev' : 'meseci')
+ case 'y': // a year / in a year / a year ago
+ return (withoutSuffix || isFuture) ? 'eno leto' : 'enim letom'
+ case 'yy': // 9 years / in 9 years / 9 years ago
+ if (dual(number)) { // 2 minutes / in 2 minutes
+ return result + ((withoutSuffix || isFuture) ? 'leti' : 'letoma')
+ }
+ if (threeFour(number)) {
+ return result + ((withoutSuffix || isFuture) ? 'leta' : 'leti')
+ }
+ return result + ((withoutSuffix || isFuture) ? 'let' : 'leti')
+ }
+}
+
+/* eslint-enable */
const locale = {
name: 'sl',
weekdays: 'nedelja_ponedeljek_torek_sreda_četrtek_petek_sobota'.split('_'),
@@ -16,26 +81,26 @@ const locale = {
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY H:mm',
- LLLL: 'dddd, D. MMMM YYYY H:mm'
+ LLLL: 'dddd, D. MMMM YYYY H:mm',
+ l: 'D. M. YYYY'
},
relativeTime: {
future: 'čez %s',
past: 'pred %s',
- s: 'nekaj sekund',
- m: 'minuta',
- mm: '%d minut',
- h: 'ura',
- hh: '%d ur',
- d: 'dan',
- dd: '%d dni',
- M: 'mesec',
- MM: '%d mesecev',
- y: 'leto',
- yy: '%d let'
+ s: translate,
+ m: translate,
+ mm: translate,
+ h: translate,
+ hh: translate,
+ d: translate,
+ dd: translate,
+ M: translate,
+ MM: translate,
+ y: translate,
+ yy: translate
}
}
dayjs.locale(locale, null, true)
export default locale
-
diff --git a/test/locale/sl.test.js b/test/locale/sl.test.js
new file mode 100644
index 000000000..672d6064b
--- /dev/null
+++ b/test/locale/sl.test.js
@@ -0,0 +1,82 @@
+import MockDate from 'mockdate'
+import dayjs from '../../src'
+import relativeTime from '../../src/plugin/relativeTime'
+import '../../src/locale/sl'
+
+dayjs.extend(relativeTime)
+
+beforeEach(() => {
+ MockDate.set(new Date())
+})
+
+afterEach(() => {
+ MockDate.reset()
+})
+
+it('Slovenian locale relative time in past and future', () => {
+ const cases = [
+ [1, 's', 'čez nekaj sekund', 'nekaj sekund'],
+ [-1, 's', 'pred nekaj sekundami', 'nekaj sekund'],
+ [1, 'm', 'čez eno minuto', 'ena minuta'],
+ [-1, 'm', 'pred eno minuto', 'ena minuta'],
+ [2, 'm', 'čez 2 minuti', '2 minuti'],
+ [-2, 'm', 'pred 2 minutama', '2 minuti'],
+ [3, 'm', 'čez 3 minute', '3 minute'],
+ [-3, 'm', 'pred 3 minutami', '3 minute'],
+ [5, 'm', 'čez 5 minut', '5 minut'],
+ [-5, 'm', 'pred 5 minutami', '5 minut'],
+ [1, 'h', 'čez eno uro', 'ena ura'],
+ [-1, 'h', 'pred eno uro', 'ena ura'],
+ [2, 'h', 'čez 2 uri', '2 uri'],
+ [-2, 'h', 'pred 2 urama', '2 uri'],
+ [3, 'h', 'čez 3 ure', '3 ure'],
+ [-3, 'h', 'pred 3 urami', '3 ure'],
+ [5, 'h', 'čez 5 ur', '5 ur'],
+ [-5, 'h', 'pred 5 urami', '5 ur'],
+ [1, 'd', 'čez en dan', 'en dan'],
+ [-1, 'd', 'pred enim dnem', 'en dan'],
+ [2, 'd', 'čez 2 dneva', '2 dneva'],
+ [-2, 'd', 'pred 2 dnevoma', '2 dneva'],
+ [3, 'd', 'čez 3 dni', '3 dni'],
+ [-3, 'd', 'pred 3 dnevi', '3 dni'],
+ [5, 'd', 'čez 5 dni', '5 dni'],
+ [-5, 'd', 'pred 5 dnevi', '5 dni'],
+ [1, 'M', 'čez en mesec', 'en mesec'],
+ [-1, 'M', 'pred enim mesecem', 'en mesec'],
+ [2, 'M', 'čez 2 meseca', '2 meseca'],
+ [-2, 'M', 'pred 2 mesecema', '2 meseca'],
+ [3, 'M', 'čez 3 mesece', '3 mesece'],
+ [-3, 'M', 'pred 3 meseci', '3 mesece'],
+ [5, 'M', 'čez 5 mesecev', '5 mesecev'],
+ [-5, 'M', 'pred 5 meseci', '5 mesecev'],
+ [1, 'y', 'čez eno leto', 'eno leto'],
+ [-1, 'y', 'pred enim letom', 'eno leto'],
+ [2, 'y', 'čez 2 leti', '2 leti'],
+ [-2, 'y', 'pred 2 letoma', '2 leti'],
+ [3, 'y', 'čez 3 leta', '3 leta'],
+ [-3, 'y', 'pred 3 leti', '3 leta'],
+ [5, 'y', 'čez 5 let', '5 let'],
+ [-5, 'y', 'pred 5 leti', '5 let']
+ // these are rounded
+ // if user decides to change rounding then it would be good to test them also
+ // [102, 's', 'čez 102 sekundi', '102 sekundi'],
+ // [-102, 's', 'pred 102 sekundama', '102 sekundi'],
+ // [103, 's', 'čez 103 sekunde', '103 sekunde'],
+ // [-103, 's', 'pred 103 sekundami', '103 sekunde'],
+ // [114, 's', 'čez 114 sekund', '114 sekund'],
+ // [-114, 's', 'pred 114 sekundami', '114 sekund'],
+ // [-102, 'm', 'čez 102 minuti', '102 minuti'],
+ // [-102, 'm', 'pred 102 minutama', '102 minuti'],
+ // [103, 'm', 'čez 103 minute', '103 minute'],
+ // [-103, 'm', 'pred 103 minutami', '103 minute'],
+ // [114, 'm', 'čez 114 minut', '114 minut'],
+ // [-114, 'm', 'pred 114 minutami', '114 minut']
+ ]
+
+ cases.forEach((c) => {
+ // With suffix
+ expect(dayjs().add(c[0], c[1]).locale('sl').fromNow()).toBe(c[2])
+ // Without suffix
+ expect(dayjs().add(c[0], c[1]).locale('sl').fromNow(true)).toBe(c[3])
+ })
+})
From 95e9458b221fe35e59ee4a160a5db247313a68fb Mon Sep 17 00:00:00 2001
From: raminjafary
Date: Tue, 19 Sep 2023 15:13:59 +0330
Subject: [PATCH 11/15] fix: change back fa locale to the Gregorian calendar
equivalent (#2411)
---
src/locale/fa.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/locale/fa.js b/src/locale/fa.js
index cbcd13c1e..cf338279f 100644
--- a/src/locale/fa.js
+++ b/src/locale/fa.js
@@ -4,11 +4,11 @@ import dayjs from 'dayjs'
const locale = {
name: 'fa',
weekdays: 'یکشنبه_دوشنبه_سهشنبه_چهارشنبه_پنجشنبه_جمعه_شنبه'.split('_'),
- weekdaysShort: 'یک_دو_سه_چه_پن_جم_شن'.split('_'),
+ weekdaysShort: 'یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_جمعه_شنبه'.split('_'),
weekdaysMin: 'ی_د_س_چ_پ_ج_ش'.split('_'),
weekStart: 6,
- months: 'فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند'.split('_'),
- monthsShort: 'فرو_ارد_خرد_تیر_مرد_شهر_مهر_آبا_آذر_دی_بهم_اسف'.split('_'),
+ months: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'),
+ monthsShort: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'),
ordinal: n => n,
formats: {
LT: 'HH:mm',
@@ -20,7 +20,7 @@ const locale = {
},
relativeTime: {
future: 'در %s',
- past: '%s قبل',
+ past: '%s پیش',
s: 'چند ثانیه',
m: 'یک دقیقه',
mm: '%d دقیقه',
From a4ff1d2febd8486959b8466186e0cfb5d3496290 Mon Sep 17 00:00:00 2001
From: Mohammed Elzanaty
Date: Tue, 19 Sep 2023 14:45:40 +0300
Subject: [PATCH 12/15] docs: update readme image tag and formating (#2409)
---
README.md | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 3a855a9c3..3e514dc88 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@ English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/R
+ alt="Day.js" />
Fast 2kB alternative to Moment.js with the same modern API
Date: Tue, 19 Sep 2023 16:58:06 +0500
Subject: [PATCH 13/15] fix: update uzbek language translation (#2327)
---
src/locale/uz-latn.js | 2 +-
src/locale/uz.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/locale/uz-latn.js b/src/locale/uz-latn.js
index 220d5d44c..7d6021921 100644
--- a/src/locale/uz-latn.js
+++ b/src/locale/uz-latn.js
@@ -20,7 +20,7 @@ const locale = {
},
relativeTime: {
future: 'Yaqin %s ichida',
- past: 'Bir necha %s oldin',
+ past: '%s oldin',
s: 'soniya',
m: 'bir daqiqa',
mm: '%d daqiqa',
diff --git a/src/locale/uz.js b/src/locale/uz.js
index 23f4042eb..e705f68bd 100644
--- a/src/locale/uz.js
+++ b/src/locale/uz.js
@@ -20,7 +20,7 @@ const locale = {
},
relativeTime: {
future: 'Якин %s ичида',
- past: 'Бир неча %s олдин',
+ past: '%s олдин',
s: 'фурсат',
m: 'бир дакика',
mm: '%d дакика',
From 4f4501256fa1bc72128aae1d841bbd782df86aed Mon Sep 17 00:00:00 2001
From: Tim Sanderson <47798264+timsand@users.noreply.github.com>
Date: Tue, 19 Sep 2023 08:46:43 -0500
Subject: [PATCH 14/15] fix: fix timezone plugin to get correct locale setting
(#2420)
Signed-off-by: Tim Sanderson
Co-authored-by: Tim Sanderson
---
src/plugin/timezone/index.js | 4 ++--
test/plugin/timezone.test.js | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js
index c8f8a4675..832fb4a73 100644
--- a/src/plugin/timezone/index.js
+++ b/src/plugin/timezone/index.js
@@ -97,7 +97,7 @@ export default (o, c, d) => {
const date = this.toDate()
const target = date.toLocaleString('en-US', { timeZone: timezone })
const diff = Math.round((date - new Date(target)) / 1000 / 60)
- let ins = d(target).$set(MS, this.$ms)
+ let ins = d(target, { locale: this.$L }).$set(MS, this.$ms)
.utcOffset((-Math.round(date.getTimezoneOffset() / 15) * 15) - diff, true)
if (keepLocalTime) {
const newOffset = ins.utcOffset()
@@ -120,7 +120,7 @@ export default (o, c, d) => {
return oldStartOf.call(this, units, startOf)
}
- const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'))
+ const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'), { locale: this.$L })
const startOfWithoutTz = oldStartOf.call(withoutTz, units, startOf)
return startOfWithoutTz.tz(this.$x.$timezone, true)
}
diff --git a/test/plugin/timezone.test.js b/test/plugin/timezone.test.js
index 2b28cc309..c4529c6c8 100644
--- a/test/plugin/timezone.test.js
+++ b/test/plugin/timezone.test.js
@@ -318,4 +318,15 @@ describe('startOf and endOf', () => {
const endOfDay = originalDay.endOf('day')
expect(endOfDay.valueOf()).toEqual(originalDay.valueOf())
})
+
+ it('preserves locality when tz is called', () => {
+ const tzWithoutLocality = dayjs.tz('2023-02-17 00:00:00', NY)
+ const tzWithLocality = dayjs.tz('2023-02-17 00:00:00', NY).locale({
+ name: 'locale_test',
+ weekStart: 3
+ })
+
+ expect(tzWithoutLocality.startOf('week').format('YYYY-MM-DD')).toEqual('2023-02-12')
+ expect(tzWithLocality.startOf('week').format('YYYY-MM-DD')).toEqual('2023-02-15')
+ })
})
From 22546357f30924fcff3b3ffa14fd04be21f97a5e Mon Sep 17 00:00:00 2001
From: Svend
Date: Tue, 19 Sep 2023 21:56:31 +0800
Subject: [PATCH 15/15] fix: update $x logic to avoid plugin error (#2429)
---
src/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/index.js b/src/index.js
index d26a401a6..061ade178 100644
--- a/src/index.js
+++ b/src/index.js
@@ -86,12 +86,12 @@ class Dayjs {
constructor(cfg) {
this.$L = parseLocale(cfg.locale, null, true)
this.parse(cfg) // for plugin
+ this.$x = this.$x || cfg.x || {}
this[IS_DAYJS] = true
}
parse(cfg) {
this.$d = parseDate(cfg)
- this.$x = cfg.x || {}
this.init()
}