Skip to content

Commit

Permalink
Merge branch 'master' into finnish-locale
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Sep 26, 2018
2 parents 24a0e1f + 5d5725b commit a61d243
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.7.7](https://github.com/iamkun/dayjs/compare/v1.7.6...v1.7.7) (2018-09-26)


### Bug Fixes

* **DST:** fix daylight saving time DST bug && add test ([#354](https://github.com/iamkun/dayjs/issues/354)) ([6fca6d5](https://github.com/iamkun/dayjs/commit/6fca6d5))

## [1.7.6](https://github.com/iamkun/dayjs/compare/v1.7.5...v1.7.6) (2018-09-25)


Expand Down
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,23 @@ class Dayjs {
const date = this.set(C.DATE, 1).set(u, n + number)
return date.set(C.DATE, Math.min(this.$D, date.daysInMonth()))
}
const instanceFactorySet = (n) => {
const date = new Date(this.$d)
date.setDate(date.getDate() + (n * number))
return wrapper(date, this)
}
if (unit === C.M) {
return instanceFactory(C.M, this.$M)
}
if (unit === C.Y) {
return instanceFactory(C.Y, this.$y)
}
if (unit === C.D) {
return instanceFactorySet(1)
}
if (unit === C.W) {
return instanceFactorySet(7)
}
let step
switch (unit) {
case C.MIN:
Expand All @@ -252,12 +263,6 @@ class Dayjs {
case C.H:
step = C.MILLISECONDS_A_HOUR
break
case C.D:
step = C.MILLISECONDS_A_DAY
break
case C.W:
step = C.MILLISECONDS_A_WEEK
break
case C.S:
step = C.MILLISECONDS_A_SECOND
break
Expand Down
27 changes: 27 additions & 0 deletions src/locale/pl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import dayjs from 'dayjs'

const locale = {
name: 'pl',
weekdays: 'Niedziela_Poniedziałek_Wtorek_Środa_Czwartek_Piątek_Sobota'.split('_'),
months: 'Styczeń_Luty_Marzec_Kwiecień_Maj_Czerwiec_Lipiec_Sierpień_Wrzesień_Październik_Listopad_Grudzień'.split('_'),
ordinal: n => `${n}.`,
relativeTime: {
future: 'za %s',
past: 'po %s',
s: 'kilka Sekund',
m: 'Minuta',
mm: '%d Minut',
h: 'Godzina',
hh: '%d Godzin',
d: 'Tydzień',
dd: '%d Tygodni',
M: 'Miesiąc',
MM: '%d Miesięcy',
y: 'Rok',
yy: '%d Lat'
}
}

dayjs.locale(locale, null, true)

export default locale
10 changes: 10 additions & 0 deletions test/manipulate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ it('Add Time days', () => {
it('Subtract Time days', () => {
expect(dayjs().subtract(1, 'days').valueOf()).toBe(moment().subtract(1, 'days').valueOf())
})

it('Add Time days (DST)', () => {
// change timezone before running test
// New Zealand (-720)
expect(dayjs('2018-04-01').add(1, 'd').format()).toBe(moment('2018-04-01').add(1, 'd').format())
expect(dayjs('2018-03-28').add(1, 'w').format()).toBe(moment('2018-03-28').add(1, 'w').format())
// London (-60)
expect(dayjs('2018-10-28').add(1, 'd').format()).toBe(moment('2018-10-28').add(1, 'd').format())
expect(dayjs('2018-10-26').add(1, 'w').format()).toBe(moment('2018-10-26').add(1, 'w').format())
})

0 comments on commit a61d243

Please sign in to comment.