Skip to content
Merged

d2m #2950

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
<div align="center">
<a href="https://go.warp.dev/dayjs" target="_blank">
<img alt="Warp sponsorship" width="400" src="https://github.com/warpdotdev/brand-assets/blob/main/Github/Sponsor/Warp-Github-LG-02.png">
<br>
<h>Warp is built for coding with multiple AI agents</b>
</a>
</div>

---

<div align="center" style="margin-top: 30px;">
<a href="https://requestly.com/?utm_source=github&utm_medium=partnered&utm_campaign=rq_dayjs_github">
<div>
<img alt="Requestly sponsorship" width="400" src="https://github.com/user-attachments/assets/24670320-997d-4d62-9bca-955c59fe883d">
</div>
<b>Requestly - Free & Open-Source alternative to Postman</b>
<div>
<sup>All-in-one platform to Test, Mock and Intercept APIs.</sup>
</div>
</a>
</div>

---

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)

<p align="center"><a href="https://day.js.org/" target="_blank" rel="noopener noreferrer"><img width="550"
Expand Down Expand Up @@ -99,12 +123,6 @@ dayjs().format('Q Do k kk X x') // more available formats

📚[Plugin List](https://day.js.org/docs/en/plugin/plugin)

### Usage Trend

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
Expand All @@ -123,12 +141,8 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<img width="70" src="https://images.opencollective.com/sight-sound/54f7220/logo/256.png?height=256">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.exoflare.com/open-source/?utm_source=dayjs&utm_campaign=open_source" target="_blank">
<img width="70" src="https://user-images.githubusercontent.com/17680888/162761622-1407a849-0c41-4591-8aa9-f98114ec2092.png">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://chudovo.com/front-end-development/" target="_blank">
<img width="70" src="https://images.opencollective.com/chudovo/3c866f5/logo/256.png?height=256">
<a href="https://opencollective.com/filerev" target="_blank">
<img width="70" src="https://images.opencollective.com/filerev/93a8f05/logo/256.png?height=256" />
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/radioplusexperts" target="_blank">
Expand All @@ -139,6 +153,14 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<img width="70" src="https://avatars.githubusercontent.com/u/13880908?s=200&v=4">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/Ayo1984" target="_blank">
<img width="70" src="https://avatars.githubusercontent.com/u/117122666?v=4">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://anonstories.com" target="_blank">
<img alt="Instagram Story Viewer" width="70" src="https://avatars.githubusercontent.com/u/240702364?v=4">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://bestkru.com/" target="_blank">
<img width="70" src="https://avatars.githubusercontent.com/u/159320286" alt="BestKru">
</a>
Expand Down
6 changes: 0 additions & 6 deletions docs/es-es/README-es-es.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ dayjs().format('Q Do k kk X x') // ahora tenemos más formatos disponibles

📚[Lista de complementos](https://day.js.org/docs/en/plugin/plugin)

### Tendencia de Uso

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## Patrocinadores

Apoya a este proyecto convirtiéndote en un patrocinador. Tu logo aparecerá aquí, enlazado a tu sitio web. [[Conviértete en un patrocinador](https://opencollective.com/dayjs#sponsor)]
Expand Down
6 changes: 0 additions & 6 deletions docs/he/README-he.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ dayjs().format('Q Do k kk X x') // כעת יותר אפשרויות זמינות

📚[רשימת תוספים](https://day.js.org/docs/en/plugin/plugin)

### מגמת השימוש

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

### ספונסרים
תמכו בפרויקט זה כדי להיות ספונסר. קבלו לוגו עם קישור לאתר שלכם שיופיע כאן.

Expand Down
6 changes: 0 additions & 6 deletions docs/ja/README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ dayjs().format('Q Do k kk X x') // 多様なフォーマットが利用可能に

📚[プラグインリスト](https://day.js.org/docs/en/plugin/plugin)

### 使用トレンド

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## ライセンス

Day.js は [MIT License](../../LICENSE) のもとで利用を許諾します。
6 changes: 0 additions & 6 deletions docs/ko/README-ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ dayjs().format('Q Do k kk X x') // more available formats

📚[플러그인 목록](https://day.js.org/docs/en/plugin/plugin)

### 사용 트렌드

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## License

Day.js는 [MIT License](./LICENSE)를 사용합니다.
6 changes: 0 additions & 6 deletions docs/pt-br/README-pt-br.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ dayjs().format('Q Do k kk X x') // mais formatos disponíveis pelo plugin

📚[Lista de Plugins](https://day.js.org/docs/en/plugin/plugin)

### Tendência de Uso

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## Patrocinadores

Ajude este projeto se tornando um patrocinador. O seu logo será exibido aqui, com um link para o seu site. [[Tornar-se um Patrocinador](https://opencollective.com/dayjs#sponsor)].
Expand Down
6 changes: 0 additions & 6 deletions docs/ru/README-ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ dayjs().format('Q Do k kk X x') // больше доступных формат

📚[Список плагинов](https://day.js.org/docs/ru/plugin/plugin)

### Тенденция использования

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## Спонсоры

Поддержите этот проект, став спонсором. Ваш логотип будет показан здесь с ссылкой на ваш веб-сайт. [[Стать спонсором](https://opencollective.com/dayjs#sponsor)]
Expand Down
6 changes: 0 additions & 6 deletions docs/si/README-si.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ dayjs().format('Q Do k kk X x') // more available formats

📚[ දිගු ලේඛනය](https://day.js.org/docs/en/plugin/plugin)

### භාවිත ප්‍රමාණයේ ප්‍රසූතිය

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## අනුග්‍රාහකයින්

අනුග්‍රහය දැක්වීමෙන් මෙම ව්‍යාපෘතියට සහාය වන්න. ඔබගේ අඩවියේ සබැඳියක් සමඟ ඔබගේ ලාංඡනය මෙහි පෙන්වනු ඇත.
Expand Down
6 changes: 0 additions & 6 deletions docs/tr/README-tr.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ dayjs().format('Q Do k kk X x') // diğer mevcut formatlar

📚[Eklenti Listesi](https://day.js.org/docs/en/plugin/plugin)

### Kullanım Trendi

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## Sponsorlar

Sponsor olarak bu projeye destek olun. Logonuz, web sayfanızın linki ile birlikte burada görünür. [[Sponsor Ol](https://opencollective.com/dayjs#sponsor)]
Expand Down
6 changes: 0 additions & 6 deletions docs/zh-cn/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ dayjs().format('Q Do k kk X x') // 使用扩展后的API

📚[插件列表](https://day.js.org/docs/zh-CN/plugin/plugin)

### 使用量趋势

<a href="https://npm-compare.com/moment,dayjs/#timeRange=THREE_YEARS" target="_blank">
<img src="https://user-images.githubusercontent.com/3455798/270162667-c7bd2ebe-675e-45c6-a2c9-dc67f3b65d6e.png">
</a>

## 开源协议

Day.js 遵循 [MIT 开源协议](../../LICENSE).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dayjs.min.js",
"types": "index.d.ts",
"scripts": {
"test": "TZ=Pacific/Auckland npm run test-tz && TZ=Europe/London npm run test-tz && TZ=America/Whitehorse npm run test-tz && npm run test-tz && jest",
"test": "TZ=Pacific/Auckland npm run test-tz && TZ=Europe/London npm run test-tz && TZ=America/Whitehorse npm run test-tz && npm run test-tz && jest --coverage --coverageThreshold='{ \"global\": { \"lines\": 100} }'",
"test-tz": "date && jest test/timezone.test --coverage=false",
"lint": "./node_modules/.bin/eslint src/* test/* build/*",
"prettier": "prettier --write \"docs/**/*.md\"",
Expand Down
14 changes: 10 additions & 4 deletions src/locale/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const numberMap = {
'٠': '0'
}

const fromArabNumeralsRegex = /[١٢٣٤٥٦٧٨٩٠]/g
const fromArabComaRegex = /،/g

const toArabNumeralsRegex = /\d/g
const toArabComaRegex = /,/g

const locale = {
name: 'ar',
weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
Expand Down Expand Up @@ -56,15 +62,15 @@ const locale = {
preparse(string) {
return string
.replace(
/[١٢٣٤٥٦٧٨٩٠]/g,
fromArabNumeralsRegex,
match => numberMap[match]
)
.replace(/،/g, ',')
.replace(fromArabComaRegex, ',')
},
postformat(string) {
return string
.replace(/\d/g, match => symbolMap[match])
.replace(/,/g, '،')
.replace(toArabNumeralsRegex, match => symbolMap[match])
.replace(toArabComaRegex, '،')
},
ordinal: n => n,
formats: {
Expand Down
87 changes: 80 additions & 7 deletions src/locale/be.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,99 @@
// Belarusian [be]
import dayjs from 'dayjs'

const monthFormat = 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_')
const monthStandalone = 'студзень_лютый_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_')

const monthShortFormat = 'студ_лют_сак_крас_трав_чэрв_ліп_жнів_вер_каст_ліст_снеж.'.split('_')
const monthShortStandalone = 'студ_лют_сак_крас_трав_чэрв_ліп_жнів_вер_каст_ліст_снеж'.split('_')

const MONTHS_IN_FORMAT = /D[oD]?(\[[^[\]]*\]|\s)+MMMM?/

function plural(word, num) {
const forms = word.split('_')
return num % 10 === 1 && num % 100 !== 11 ? forms[0] : (num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) ? forms[1] : forms[2]) // eslint-disable-line
}
function relativeTimeWithPlural(number, withoutSuffix, key) {
const format = {
ss: withoutSuffix ? 'секунда_секунды_секунд' : 'секунду_секунды_секунд',
mm: withoutSuffix ? 'хвіліна_хвіліны_хвілін' : 'хвіліну_хвіліны_хвілін',
hh: withoutSuffix ? 'гадзіна_гадзіны_гадзін' : 'гадзіну_гадзіны_гадзін',
dd: 'дзень_дні_дзён',
MM: 'месяц_месяцы_месяцаў',
yy: 'год_гады_гадоў'
}
if (key === 'm') {
return withoutSuffix ? 'хвіліна' : 'хвіліну'
} else if (key === 'h') {
return withoutSuffix ? 'гадзіна' : 'гадзіну'
}

return `${number} ${plural(format[key], +number)}`
}

const months = (dayjsInstance, format) => {
if (MONTHS_IN_FORMAT.test(format)) {
return monthFormat[dayjsInstance.month()]
}
return monthStandalone[dayjsInstance.month()]
}
months.s = monthStandalone
months.f = monthFormat

const monthsShort = (dayjsInstance, format) => {
if (MONTHS_IN_FORMAT.test(format)) {
return monthShortFormat[dayjsInstance.month()]
}
return monthShortStandalone[dayjsInstance.month()]
}
monthsShort.s = monthShortStandalone
monthsShort.f = monthShortFormat

const locale = {
name: 'be',
weekdays: 'нядзелю_панядзелак_аўторак_сераду_чацвер_пятніцу_суботу'.split('_'),
months: 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_'),
weekdays: 'нядзеля_панядзелак_аўторак_серада_чацвер_пятніца_субота'.split('_'),
weekdaysShort: 'няд_пнд_аўт_сер_чцв_пят_суб'.split('_'),
weekdaysMin: 'нд_пн_аў_ср_чц_пт_сб'.split('_'),
months,
monthsShort,
weekStart: 1,
weekdaysShort: 'нд_пн_ат_ср_чц_пт_сб'.split('_'),
monthsShort: 'студ_лют_сак_крас_трав_чэрв_ліп_жнів_вер_каст_ліст_снеж'.split('_'),
weekdaysMin: 'нд_пн_ат_ср_чц_пт_сб'.split('_'),
ordinal: n => n,
yearStart: 4,
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'
},
relativeTime: {
future: 'праз %s',
past: '%s таму',
s: 'некалькі секунд',
m: relativeTimeWithPlural,
mm: relativeTimeWithPlural,
h: relativeTimeWithPlural,
hh: relativeTimeWithPlural,
d: 'дзень',
dd: relativeTimeWithPlural,
M: 'месяц',
MM: relativeTimeWithPlural,
y: 'год',
yy: relativeTimeWithPlural
},
ordinal: n => n,
meridiem: (hour) => {
if (hour < 4) {
return 'ночы'
} else if (hour < 12) {
return 'раніцы'
} else if (hour < 17) {
return 'дня'
}
return 'вечара'
}
}

dayjs.locale(locale, null, true)

export default locale

2 changes: 1 addition & 1 deletion src/locale/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const locale = {
s: 'qualche secondo',
m: 'un minuto',
mm: '%d minuti',
h: 'un\' ora',
h: 'un\'ora',
hh: '%d ore',
d: 'un giorno',
dd: '%d giorni',
Expand Down
11 changes: 10 additions & 1 deletion src/plugin/devHelper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export default (o, c, d) => {
}
return oldLocale(preset, object, isLocal)
}

const oldDiff = proto.diff
proto.diff = function (date, unit, float) {
const isInvalidDate = !date || !d(date).isValid()
if (isInvalidDate) {
console.warn('Invalid usage: diff() requires a valid comparison date as the first argument. https://day.js.org/docs/en/display/difference')
}

return oldDiff.call(this, date, unit, float)
}
}
}

Loading