Skip to content

Commit

Permalink
Merge pull request #962 from iamkun/dev
Browse files Browse the repository at this point in the history
D2M
  • Loading branch information
andrewhood125ruhuc committed Dec 16, 2027
2 parents 871ce85 + acbe830 commit 6e0938e
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ dayjs().format('Q Do k kk X x') // more available formats

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/dayjs#sponsor)]

Day.js is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial.
<a href="https://tracking.gitads.io/?repo=dayjs" target="_blank" rel="noopener noreferrer">
<img src="https://images.gitads.io/dayjs" alt="sponsors"></a>

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Dayjs {
const date = this.clone().set(C.DATE, 1)
date.$d[name](arg)
date.init()
this.$d = date.set(C.DATE, Math.min(this.$D, date.daysInMonth())).toDate()
this.$d = date.set(C.DATE, Math.min(this.$D, date.daysInMonth())).$d
} else if (name) this.$d[name](arg)

this.init()
Expand Down
41 changes: 41 additions & 0 deletions src/locale/es-pr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Spanish (Puerto Rico) [es-PR]
import dayjs from 'dayjs'

const locale = {
name: 'es-pr',
monthsShort: 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'),
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('_'),
weekStart: 1,
formats: {
LT: 'h:mm A',
LTS: 'h:mm:ss A',
L: 'MM/DD/YYYY',
LL: 'D [de] MMMM [de] YYYY',
LLL: 'D [de] MMMM [de] YYYY h:mm A',
LLLL: 'dddd, D [de] MMMM [de] YYYY h:mm A'
},
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}º`
}

dayjs.locale(locale, null, true)

export default locale

1 change: 1 addition & 0 deletions src/locale/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const locale = {
months: 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'),
monthsShort: 'janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.'.split('_'),
weekStart: 1,
yearStart: 4,
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
Expand Down
40 changes: 40 additions & 0 deletions src/locale/ht.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Haitian Creole (Haiti) [ht]
import dayjs from 'dayjs'

const locale = {
name: 'ht',
weekdays: 'dimanch_lendi_madi_mèkredi_jedi_vandredi_samdi'.split('_'),
months: 'janvye_fevriye_mas_avril_me_jen_jiyè_out_septanm_oktòb_novanm_desanm'.split('_'),
weekdaysShort: 'dim._len._mad._mèk._jed._van._sam.'.split('_'),
monthsShort: 'jan._fev._mas_avr._me_jen_jiyè._out_sept._okt._nov._des.'.split('_'),
weekdaysMin: 'di_le_ma_mè_je_va_sa'.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'
},
relativeTime: {
future: 'nan %s',
past: 'sa gen %s',
s: 'kèk segond',
m: 'yon minit',
mm: '%d minit',
h: 'inèdtan',
hh: '%d zè',
d: 'yon jou',
dd: '%d jou',
M: 'yon mwa',
MM: '%d mwa',
y: 'yon ane',
yy: '%d ane'
}
}

dayjs.locale(locale, null, true)

export default locale

26 changes: 25 additions & 1 deletion test/plugin/utc-utcOffset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ it('clone', () => {

it('immutable', () => {
const d = dayjs()
const du = d.utcOffset(9)
const du = d.utcOffset(d.utcOffset() + 1)
expect(d.utcOffset()).not.toBe(du.utcOffset())
expect(d.format()).not.toBe(du.format())
})
Expand Down Expand Up @@ -76,6 +76,30 @@ test('change hours when changing the utc offset in UTC mode', () => {
expect(d.utcOffset(-1380).format('HH:mm')).toBe('07:31')
})

test('correctly set and add hours in offset mode', () => {
const d10 = dayjs('2000-01-30T06:31:00+10:00').utcOffset(10)
const dm8 = dayjs('2000-01-30T06:31:00-08:00').utcOffset(-8)

expect(d10.hour(5).hour()).toBe(5)
expect(d10.hour(5).add(1, 'hour').hour()).toBe(6)
expect(d10.hour(5).add(-10, 'hour').hour()).toBe(19)

expect(dm8.hour(5).hour()).toBe(5)
expect(dm8.hour(5).add(1, 'hour').hour()).toBe(6)
expect(dm8.hour(5).add(-10, 'hour').hour()).toBe(19)
})

test('keep hours when adding month in offset mode', () => {
const d10 = dayjs('2000-01-30T06:31:00+10:00').utcOffset(10)
const dm8 = dayjs('2000-01-30T06:31:00-08:00').utcOffset(-8)

expect(d10.add(1, 'month').hour()).toBe(6)
expect(dm8.add(1, 'month').hour()).toBe(6)

expect(d10.add(-2, 'month').hour()).toBe(6)
expect(dm8.add(-2, 'month').hour()).toBe(6)
})

test('utc costrustor', () => {
const d = new Date(2019, 8, 11, 0, 0, 0).getTime()
expect(moment(d).utc().utcOffset(480).valueOf())
Expand Down
10 changes: 5 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ declare function dayjs (date?: dayjs.ConfigType): dayjs.Dayjs

declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, strict?: boolean): dayjs.Dayjs

declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean): dayjs.Dayjs
declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: LocalePresetType, strict?: boolean): dayjs.Dayjs

declare namespace dayjs {
export type ConfigType = string | number | Date | Dayjs

export type OptionType = { locale?: string, format?: string, utc?: boolean } | string | string[]
export type OptionType = { locale?: LocalePresetType, format?: string, utc?: boolean } | string | string[]

type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms'
export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year' | 'date' | UnitTypeShort;
Expand Down Expand Up @@ -96,16 +96,16 @@ declare namespace dayjs {

isAfter(date: ConfigType, unit?: OpUnitType): boolean

locale(): string
locale(): LocalePresetType

locale(preset: string | ILocale, object?: Partial<ILocale>): Dayjs
locale(preset: LocalePresetType | ILocale, object?: Partial<ILocale>): Dayjs
}

export type PluginFunc<T = unknown> = (option: T, c: typeof Dayjs, d: typeof dayjs) => void

export function extend<T = unknown>(plugin: PluginFunc<T>, option?: T): Dayjs

export function locale(preset?: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string
export function locale(preset?: LocalePresetType | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string

export function isDayjs(d: any): d is Dayjs

Expand Down
137 changes: 137 additions & 0 deletions types/locale/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,140 @@ declare interface ILocale {
yy: string
}>
}

declare type LocalePresetType =
| 'af'
| 'ar-dz'
| 'ar-kw'
| 'ar-ly'
| 'ar-ma'
| 'ar-sa'
| 'ar-tn'
| 'ar'
| 'az'
| 'be'
| 'bg'
| 'bi'
| 'bm'
| 'bn'
| 'bo'
| 'br'
| 'bs'
| 'ca'
| 'cs'
| 'cv'
| 'cy'
| 'da'
| 'de-at'
| 'de-ch'
| 'de'
| 'dv'
| 'el'
| 'en-SG'
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