Skip to content

Commit

Permalink
Merge pull request #1459 from iamkun/dev
Browse files Browse the repository at this point in the history
D2M
  • Loading branch information
andrewhood125ruhuc committed Dec 14, 2028
2 parents 5ab05e9 + 30a57ec commit d029f1a
Show file tree
Hide file tree
Showing 37 changed files with 241 additions and 58 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/R
src="https://user-images.githubusercontent.com/17680888/39081119-3057bbe2-456e-11e8-862c-646133ad4b43.png"
alt="Day.js"></a></p>
<p align="center">Fast <b>2kB</b> alternative to Moment.js with the same modern API</p>
<p align="center">
<a href="https://www.duohui.cn?utm_source=dayjs" title="多会 - 专业活动管理系统" target="_blank"><img height="120px" width="120px" alt="多会" src="https://user-images.githubusercontent.com/17680888/97983132-c433bd80-1e0f-11eb-8dde-9f216e05ee8a.png"/></a></p>
<p align="center">
<a href="https://unpkg.com/dayjs/dayjs.min.js"><img
src="http://img.badgesize.io/https://unpkg.com/dayjs/dayjs.min.js?compression=gzip&style=flat-square"
Expand Down
22 changes: 13 additions & 9 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,27 @@ async function listLocaleJson(localeArr) {

(async () => {
try {
/* eslint-disable no-restricted-syntax, no-await-in-loop */
// We use await-in-loop to make rollup run sequentially to save on RAM
const locales = await promisifyReadDir(localePath)
locales.forEach((l) => {
build(configFactory({
for (const l of locales) {
// run builds sequentially to limit RAM usage
await build(configFactory({
input: `./src/locale/${l}`,
fileName: `./locale/${l}`,
name: `dayjs_locale_${formatName(l)}`
}))
})
}

const plugins = await promisifyReadDir(path.join(__dirname, '../src/plugin'))
plugins.forEach((l) => {
build(configFactory({
input: `./src/plugin/${l}/index`,
fileName: `./plugin/${l}.js`,
name: `dayjs_plugin_${formatName(l)}`
for (const plugin of plugins) {
// run builds sequentially to limit RAM usage
await build(configFactory({
input: `./src/plugin/${plugin}/index`,
fileName: `./plugin/${plugin}.js`,
name: `dayjs_plugin_${formatName(plugin)}`
}))
})
}

build(configFactory({
input: './src/index.js',
Expand Down
7 changes: 4 additions & 3 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const babel = require('rollup-plugin-babel')
const uglify = require('rollup-plugin-uglify')
const { terser } = require('rollup-plugin-terser')

module.exports = (config) => {
const { input, fileName, name } = config
Expand All @@ -13,7 +13,7 @@ module.exports = (config) => {
babel({
exclude: 'node_modules/**'
}),
uglify()
terser()
]
},
output: {
Expand All @@ -22,7 +22,8 @@ module.exports = (config) => {
name: name || 'dayjs',
globals: {
dayjs: 'dayjs'
}
},
compact: true
}
}
}
12 changes: 6 additions & 6 deletions docs/es-es/README-es-es.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center"><a href="#" target="_blank" rel="noopener noreferrer"><img width="550"
src="https://user-images.githubusercontent.com/17680888/39081119-3057bbe2-456e-11e8-862c-646133ad4b43.png"
alt="Day.js"></a></p>
<p align="center">Alternativa ligera, <b>2kB</b>, a Moment.js, con la misma API moderna</p>
<p align="center">Alternativa rápida y ligera <b>2kB</b> a Moment.js, con la misma API moderna</p>
<br>
<p align="center">
<a href="https://unpkg.com/dayjs/dayjs.min.js"><img
Expand All @@ -21,7 +21,7 @@
</a>
</p>

> Day.js es una librería JavaScript minimalista que analiza, valida, manipula y muestra fechas y horas para navegadores modernos, manteniendo una API casi totalmente compatible con Moment.js. Si usas Moment.js, ya sabes usar Day.js.
> Day.js es una librería minimalista para JavaScript que analiza, valida, manipula y muestra fechas y horas para navegadores modernos, manteniendo una API casi completamente compatible con Moment.js. Si usas o has usado Moment.js, ya sabes usar Day.js
```js
dayjs()
Expand All @@ -42,9 +42,9 @@ dayjs()

# Primeros pasos

### Documentation
### Documentación

You can find for more details, API, and other docs on [day.js.org](https://day.js.org/) website.
Puedes encontrar más detalles, la API y otros documentos en [day.js.org](https://day.js.org/) el sitio web.

## Instalación

Expand All @@ -56,7 +56,7 @@ npm install dayjs --save

## API

Usar las API de Day.js para analizar, validar, manipular y mostrar fechas y horas es muy sencillo.
Es fácil el usar las APIs de Day.js para analizar, validar, manipular y mostrar fechas y horas.

```javascript
dayjs('2018-08-08') // analiza
Expand Down Expand Up @@ -125,4 +125,4 @@ Por favor, danos una 💖 estrella 💖 para apoyarnos. Gracias.

## Licencia

Day.js está licenciada bajo la [Licencia MIT](./LICENSE).
Day.js está licenciado bajo la [Licencia MIT](./LICENSE).
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@
"ncp": "^2.0.0",
"pre-commit": "^1.2.2",
"prettier": "^1.16.1",
"rollup": "^0.57.1",
"rollup-plugin-babel": "^4.0.0-beta.4",
"rollup-plugin-uglify": "^3.0.0",
"rollup": "^2.45.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-terser": "^7.0.2",
"size-limit": "^0.18.0",
"typescript": "^2.8.3"
},
"dependencies": {}
}
}
1 change: 1 addition & 0 deletions src/locale/ar-dz.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const locale = {
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd D MMMM YYYY HH:mm'
},
meridiem: hour => (hour > 12 ? 'ص' : 'م'),
relativeTime: {
future: 'في %s',
past: 'منذ %s',
Expand Down
1 change: 1 addition & 0 deletions src/locale/ar-kw.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const locale = {
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd D MMMM YYYY HH:mm'
},
meridiem: hour => (hour > 12 ? 'ص' : 'م'),
relativeTime: {
future: 'في %s',
past: 'منذ %s',
Expand Down
1 change: 1 addition & 0 deletions src/locale/ar-ly.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const locale = {
monthsShort: 'يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'.split('_'),
weekdaysMin: 'ح_ن_ث_ر_خ_ج_س'.split('_'),
ordinal: n => n,
meridiem: hour => (hour > 12 ? 'ص' : 'م'),
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
Expand Down
1 change: 1 addition & 0 deletions src/locale/ar-ma.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const locale = {
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd D MMMM YYYY HH:mm'
},
meridiem: hour => (hour > 12 ? 'ص' : 'م'),
relativeTime: {
future: 'في %s',
past: 'منذ %s',
Expand Down
1 change: 1 addition & 0 deletions src/locale/ar-sa.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const locale = {
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd D MMMM YYYY HH:mm'
},
meridiem: hour => (hour > 12 ? 'ص' : 'م'),
relativeTime: {
future: 'في %s',
past: 'منذ %s',
Expand Down
1 change: 1 addition & 0 deletions src/locale/ar-tn.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const locale = {
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd D MMMM YYYY HH:mm'
},
meridiem: hour => (hour > 12 ? 'ص' : 'م'),
relativeTime: {
future: 'في %s',
past: 'منذ %s',
Expand Down
2 changes: 1 addition & 1 deletion src/locale/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const locale = {
weekdays: 'রবিবার_সোমবার_মঙ্গলবার_বুধবার_বৃহস্পতিবার_শুক্রবার_শনিবার'.split('_'),
months: 'জানুয়ারি_ফেব্রুয়ারি_মার্চ_এপ্রিল_মে_জুন_জুলাই_আগস্ট_সেপ্টেম্বর_অক্টোবর_নভেম্বর_ডিসেম্বর'.split('_'),
weekdaysShort: 'রবি_সোম_মঙ্গল_বুধ_বৃহস্পতি_শুক্র_শনি'.split('_'),
monthsShort: 'জানু_ফেব_মার্চ_এপ্র_মে_জুন_জুল_আগ_সেপ্ট_অক্টো_নভে_ডিসে'.split('_'),
monthsShort: 'জানু_ফেব্রু_মার্চ_এপ্রিল_মে_জুন_জুলাই_আগস্ট_সেপ্ট_অক্টো_নভে_ডিসে'.split('_'),
weekdaysMin: 'রবি_সোম_মঙ্গ_বুধ_বৃহঃ_শুক্র_শনি'.split('_'),
preparse(string) {
return string.replace(/[১২৩৪৫৬৭৮৯০]/g, match => numberMap[match])
Expand Down
1 change: 1 addition & 0 deletions src/locale/br.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function relativeTimeWithMutation(number, withoutSuffix, key) {
return `${number} ${mutation(format[key], number)}`
}
function specialMutationForYears(number) {
/* istanbul ignore next line */
switch (lastNumber(number)) {
case 1:
case 3:
Expand Down
2 changes: 1 addition & 1 deletion src/locale/es-do.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const locale = {
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('_'),
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('_'),
weekStart: 1,
relativeTime: {
Expand Down
2 changes: 1 addition & 1 deletion src/locale/es-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const locale = {
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('_'),
months: 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'),
weekStart: 1,
formats: {
LT: 'h:mm A',
Expand Down
2 changes: 1 addition & 1 deletion src/locale/es-us.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const locale = {
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('_'),
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',
Expand Down
2 changes: 1 addition & 1 deletion src/locale/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const locale = {
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('_'),
months: 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_'),
weekStart: 1,
formats: {
LT: 'H:mm',
Expand Down
1 change: 1 addition & 0 deletions src/locale/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const locale = {
monthsShort: 'tammi_helmi_maalis_huhti_touko_kesä_heinä_elo_syys_loka_marras_joulu'.split('_'),
ordinal: n => `${n}.`,
weekStart: 1,
yearStart: 4,
relativeTime: {
future: '%s päästä',
past: '%s sitten',
Expand Down
13 changes: 12 additions & 1 deletion src/locale/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const locale = {
months,
monthsShort,
weekStart: 1,
yearStart: 4,
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
Expand All @@ -76,7 +77,17 @@ const locale = {
y: 'год',
yy: relativeTimeWithPlural
},
ordinal: n => n
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)
Expand Down
2 changes: 1 addition & 1 deletion src/locale/sl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const locale = {
weekdaysShort: 'ned._pon._tor._sre._čet._pet._sob.'.split('_'),
monthsShort: 'jan._feb._mar._apr._maj._jun._jul._avg._sep._okt._nov._dec.'.split('_'),
weekdaysMin: 'ne_po_to_sr_če_pe_so'.split('_'),
ordinal: n => n,
ordinal: n => `${n}.`,
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
Expand Down
1 change: 1 addition & 0 deletions src/locale/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const locale = {
months: 'januari_februari_mars_april_maj_juni_juli_augusti_september_oktober_november_december'.split('_'),
monthsShort: 'jan_feb_mar_apr_maj_jun_jul_aug_sep_okt_nov_dec'.split('_'),
weekStart: 1,
yearStart: 4,
ordinal: (n) => {
const b = n % 10
const o = (b === 1) || (b === 2) ? 'a' : 'e'
Expand Down
2 changes: 1 addition & 1 deletion src/locale/uk.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const locale = {
weekdaysShort: 'ндл_пнд_втр_срд_чтв_птн_сбт'.split('_'),
weekdaysMin: 'нд_пн_вт_ср_чт_пт_сб'.split('_'),
months,
monthsShort: 'січ_лют_бер_квiт_трав_черв_лип_серп_вер_жовт_лист_груд'.split('_'),
monthsShort: 'січ_лют_бер_квіт_трав_черв_лип_серп_вер_жовт_лист_груд'.split('_'),
weekStart: 1,
relativeTime: {
future: 'за %s',
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const match3 = /\d{3}/ // 000 - 999
const match4 = /\d{4}/ // 0000 - 9999
const match1to2 = /\d\d?/ // 0 - 99
const matchSigned = /[+-]?\d+/ // -inf - inf
const matchOffset = /[+-]\d\d:?(\d\d)?/ // +00:00 -00:00 +0000 or -0000 +00
const matchOffset = /[+-]\d\d:?(\d\d)?|Z/ // +00:00 -00:00 +0000 or -0000 +00 or Z
const matchWord = /\d*[^\s\d-_:/()]+/ // Word

let locale = {}

function offsetFromString(string) {
if (!string) return 0
if (string === 'Z') return 0
const parts = string.match(/([+-]|\d\d)/g)
const minutes = +(parts[1] * 60) + (+parts[2] || 0)
return minutes === 0 ? 0 : parts[0] === '+' ? -minutes : minutes // eslint-disable-line no-nested-ternary
Expand Down
1 change: 1 addition & 0 deletions src/plugin/devHelper/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-console */
export default (o, c, d) => {
/* istanbul ignore next line */
if (!process || process.env.NODE_ENV !== 'production') {
const proto = c.prototype
const oldParse = proto.parse
Expand Down
10 changes: 8 additions & 2 deletions src/plugin/duration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class Duration {
constructor(input, unit, locale) {
this.$d = {}
this.$l = locale
if (input === undefined) {
this.$ms = 0
this.parseFromMilliseconds()
}
if (unit) {
return wrapper(input * unitToMS[prettyUnit(unit)], this)
}
Expand All @@ -79,15 +83,17 @@ class Duration {
if (typeof input === 'string') {
const d = input.match(durationRegex)
if (d) {
[,,
const properties = d.slice(2)
const numberD = properties.map(value => Number(value));
[
this.$d.years,
this.$d.months,
this.$d.weeks,
this.$d.days,
this.$d.hours,
this.$d.minutes,
this.$d.seconds
] = d
] = numberD
this.calMilliseconds()
return this
}
Expand Down
10 changes: 5 additions & 5 deletions src/plugin/timezone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const getDateTimeFormat = (timezone, options = {}) => {
export default (o, c, d) => {
let defaultTimezone

const localUtcOffset = d().utcOffset()

const makeFormatParts = (timestamp, timezone, options = {}) => {
const date = new Date(timestamp)
const dtf = getDateTimeFormat(timezone, options)
Expand Down Expand Up @@ -96,9 +94,11 @@ export default (o, c, d) => {

proto.tz = function (timezone = defaultTimezone, keepLocalTime) {
const oldOffset = this.utcOffset()
const target = this.toDate().toLocaleString('en-US', { timeZone: timezone })
const diff = Math.round((this.toDate() - new Date(target)) / 1000 / 60)
let ins = d(target).$set(MS, this.$ms).utcOffset(localUtcOffset - diff, true)
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)
.utcOffset((-Math.round(date.getTimezoneOffset() / 15) * 15) - diff, true)
if (keepLocalTime) {
const newOffset = ins.utcOffset()
ins = ins.add(oldOffset - newOffset, MIN)
Expand Down
Loading

0 comments on commit d029f1a

Please sign in to comment.