Skip to content

Commit 82babd6

Browse files
iamkunvatanak10veeceeyTest Userclaude
authored
D2M (#3018)
* chore: update demo * chore: update * chore: update doc * chore: update doc * chore: update doc * chore: update doc * chore: update doc * chore: update doc * chore: update doc * chore: update doc * fix: Update locale km.js to support meridiem (#3017) * Update km.js contribute meridiem * Simplify meridiem function in km.js --------- Co-authored-by: iamkun <kunhello@outlook.com> * fix: update updateLocale plugin to merge nested object properties instead of replacing (#3012) When updating a locale with a partial nested object (e.g., only one key in `formats`), the plugin now merges the new values into the existing object rather than replacing the entire object. This preserves other keys that were not included in the update. Arrays and non-object values continue to be replaced entirely. Fixes #1118 Co-authored-by: Test User <test@example.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> * chore: fix lint error --------- Co-authored-by: Serey Vatanak <koeurnsereyvatanak@gmail.com> Co-authored-by: Varun Chawla <34209028+veeceey@users.noreply.github.com> Co-authored-by: Test User <test@example.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2 parents 02b7a5c + bbe4ab1 commit 82babd6

7 files changed

Lines changed: 60 additions & 47 deletions

File tree

README.md

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
<div align="center">
2-
<a href="https://go.warp.dev/dayjs" target="_blank">
3-
<img alt="Warp sponsorship" width="400" src="https://github.com/warpdotdev/brand-assets/blob/main/Github/Sponsor/Warp-Github-LG-02.png">
4-
<br>
5-
<h>Warp is built for coding with multiple AI agents</b>
6-
</a>
7-
</div>
8-
9-
---
10-
11-
<div align="center" style="margin-top: 30px;">
12-
<a href="https://requestly.com/?utm_source=github&utm_medium=partnered&utm_campaign=rq_dayjs_github">
13-
<div>
14-
<img alt="Requestly sponsorship" width="400" src="https://github.com/user-attachments/assets/24670320-997d-4d62-9bca-955c59fe883d">
15-
</div>
16-
<b>Requestly - Free & Open-Source alternative to Postman</b>
17-
<div>
18-
<sup>All-in-one platform to Test, Mock and Intercept APIs.</sup>
19-
</div>
20-
</a>
21-
</div>
22-
23-
---
24-
251
English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/README-ja.md) | [Português Brasileiro](./docs/pt-br/README-pt-br.md) | [한국어](./docs/ko/README-ko.md) | [Español (España)](./docs/es-es/README-es-es.md) | [Русский](./docs/ru/README-ru.md) | [Türkçe](./docs/tr/README-tr.md) | [සිංහල](./docs/si/README-si.md) | [עברית](./docs/he/README-he.md)
262

273
<p align="center"><a href="https://day.js.org/" target="_blank" rel="noopener noreferrer"><img width="550"
@@ -145,22 +121,22 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
145121
<img width="70" src="https://images.opencollective.com/filerev/93a8f05/logo/256.png?height=256" />
146122
</a>
147123
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
148-
<a href="https://github.com/radioplusexperts" target="_blank">
149-
<img width="70" src="https://avatars.githubusercontent.com/u/188567998?v=4">
124+
<a href="https://opencollective.com/carboneio" target="_blank">
125+
<img width="70" src="https://images.opencollective.com/carboneio/fe2066c/logo/256.png?height=256">
150126
</a>
151127
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
152-
<a href="https://github.com/storyblok" target="_blank">
153-
<img width="70" src="https://avatars.githubusercontent.com/u/13880908?s=200&v=4">
154-
</a>
155-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
156-
<a href="https://github.com/Ayo1984" target="_blank">
157-
<img width="70" src="https://avatars.githubusercontent.com/u/117122666?v=4">
128+
<a href="https://github.com/radioplusexperts" target="_blank">
129+
<img width="70" src="https://avatars.githubusercontent.com/u/188567998?v=4">
158130
</a>
159131
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
160132
<a href="https://anonstories.com" target="_blank">
161133
<img alt="Instagram Story Viewer" width="70" src="https://avatars.githubusercontent.com/u/240702364?v=4">
162134
</a>
163135
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
136+
<a href="https://automatio.ai" target="_blank" alt="Automatio AI">
137+
<img width="70" src="https://avatars.githubusercontent.com/u/1984909?v=4" />
138+
</a>
139+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
164140
<a href="https://bestkru.com/" target="_blank">
165141
<img width="70" src="https://avatars.githubusercontent.com/u/159320286" alt="BestKru">
166142
</a>
@@ -173,13 +149,17 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
173149
<img width="70" src="https://github.com/user-attachments/assets/3fbc86c5-98a9-49c2-beae-1969026fcd76" alt="Route Optimizer and Route Planner Software">
174150
</a>
175151
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
176-
<a href="https://github.com/Nftsworld007" target="_blank">
177-
<img width="70" src="https://avatars.githubusercontent.com/u/133202490">
178-
</a>
179-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
180152
<a href="https://github.com/sentdm" target="_blank">
181153
<img width="70" src="https://avatars.githubusercontent.com/u/153308555?s=200&v=4">
182154
</a>
155+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
156+
<a href="https://github.com/blacksandsmedia" target="_blank">
157+
<img width="70" src="https://avatars.githubusercontent.com/u/116517387?v=4">
158+
</a>
159+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
160+
<a href="https://github.com/mvpsnet" target="_blank">
161+
<img width="70" src="https://avatars.githubusercontent.com/u/89784111?s=96&v=4">
162+
</a>
183163

184164

185165
## Contributors

docs/demo/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ dayjs().endOf('year').format()
4949

5050
// week
5151
dayjs().week()
52+
53+
// weekday
54+
dayjs().weekday()

docs/fr/README-fr.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ Soutenez ce projet en devenant sponsor. Votre logo apparaîtra ici avec un lien
131131
<img width="70" src="https://avatars.githubusercontent.com/u/65305317?v=4">
132132
</a>
133133
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
134-
<a href="https://github.com/storyblok" target="_blank">
135-
<img width="70" src="https://avatars.githubusercontent.com/u/13880908?s=200&v=4">
136-
</a>
137-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
138134
<a href="https://www.exoflare.com/open-source/?utm_source=dayjs&utm_campaign=open_source" target="_blank">
139135
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
140136
</a>

docs/sw/README-sw.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ Toa mchango wako kwa huu mradi kwa kuwa mfadhili. Nembo yako itaonekana hapa pam
134134
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
135135
</a>
136136
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
137-
<a href="https://github.com/storyblok" target="_blank">
138-
<img width="70" src="https://avatars.githubusercontent.com/u/13880908?s=200&v=4">
139-
</a>
140-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
141137
<a href="https://bestkru.com/" target="_blank">
142138
<img width="70" src="https://avatars.githubusercontent.com/u/159320286" alt="BestKru">
143139
</a>
@@ -160,4 +156,4 @@ Na ahsante kwa wafadhili wote! 🙏
160156

161157
## Leseni
162158

163-
Day.js ipo chini ya kibali cha [leseni ya MTI](./LICENSE).
159+
Day.js ipo chini ya kibali cha [leseni ya MTI](./LICENSE).

src/locale/km.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const locale = {
3232
MM: '%d ខែ',
3333
y: 'មួយឆ្នាំ',
3434
yy: '%d ឆ្នាំ'
35-
}
35+
},
36+
meridiem: hour => (hour > 12 ? 'ល្ងាច' : 'ព្រឹក')
3637
}
3738

3839
dayjs.locale(locale, null, true)

src/plugin/updateLocale/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ export default (option, Dayjs, dayjs) => {
55
if (!localeConfig) return
66
const customConfigKeys = customConfig ? Object.keys(customConfig) : []
77
customConfigKeys.forEach((c) => {
8-
localeConfig[c] = customConfig[c]
8+
if (localeConfig[c] && customConfig[c] && typeof localeConfig[c] === 'object' && typeof customConfig[c] === 'object'
9+
&& !Array.isArray(localeConfig[c])) {
10+
localeConfig[c] = {
11+
...localeConfig[c],
12+
...customConfig[c]
13+
}
14+
} else {
15+
localeConfig[c] = customConfig[c]
16+
}
917
})
1018
return localeConfig // eslint-disable-line consistent-return
1119
}

test/plugin/updateLocale.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ describe('Update locale', () => {
6969
.toEqual(moment().format(formatString))
7070
})
7171

72+
it('Partial update to nested object (formats)', () => {
73+
dayjs.locale('en')
74+
// First, get the original formats
75+
const originalLocale = dayjs.Ls.en
76+
const originalLT = originalLocale.formats && originalLocale.formats.LT
77+
78+
// Update only L format
79+
dayjs.updateLocale('en', {
80+
formats: {
81+
L: 'DD/MM/YYYY'
82+
}
83+
})
84+
85+
const updatedLocale = dayjs.Ls.en
86+
// The updated key should have the new value
87+
expect(updatedLocale.formats.L).toBe('DD/MM/YYYY')
88+
// Other keys in formats should be preserved
89+
expect(updatedLocale.formats.LT).toBe(originalLT)
90+
})
91+
92+
it('Non-object values should still be replaced entirely', () => {
93+
const newMonths = new Array(12).fill('newMonth')
94+
dayjs.updateLocale('en', {
95+
months: newMonths
96+
})
97+
const updatedLocale = dayjs.Ls.en
98+
expect(updatedLocale.months).toEqual(newMonths)
99+
})
100+
72101
it('Update invalid date string', () => {
73102
const locale = 'en'
74103
const localeSetting = { invalidDate: 'bad date' }

0 commit comments

Comments
 (0)