Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: iamkun/dayjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.8.27
Choose a base ref
...
head repository: iamkun/dayjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.8.28
Choose a head ref
  • 4 commits
  • 5 files changed
  • 3 contributors

Commits on May 22, 2020

  1. Copy the full SHA
    a08756e View commit details

Commits on May 28, 2020

  1. Copy the full SHA
    fa2ec7f View commit details
  2. Merge pull request #919 from iamkun/dev

    D2M
    iamkun authored May 28, 2020
    Copy the full SHA
    8cd5745 View commit details
  3. chore(release): 1.8.28 [skip ci]

    ## [1.8.28](v1.8.27...v1.8.28) (2020-05-28)
    
    ### Bug Fixes
    
    * Fix CustomParseFormat plugin month index error ([#918](#918)) ([fa2ec7f](fa2ec7f)), closes [#915](#915)
    * Update Ukrainian (uk) locale monthFormat and monthStandalone ([#899](#899)) ([a08756e](a08756e))
    semantic-release-bot committed May 28, 2020
    Copy the full SHA
    bc07156 View commit details
Showing with 48 additions and 7 deletions.
  1. +8 −0 CHANGELOG.md
  2. +15 −1 src/locale/uk.js
  3. +6 −6 src/plugin/customParseFormat/index.js
  4. +13 −0 test/locale/uk.test.js
  5. +6 −0 test/plugin/customParseFormat.test.js
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [1.8.28](https://github.com/iamkun/dayjs/compare/v1.8.27...v1.8.28) (2020-05-28)


### Bug Fixes

* Fix CustomParseFormat plugin month index error ([#918](https://github.com/iamkun/dayjs/issues/918)) ([fa2ec7f](https://github.com/iamkun/dayjs/commit/fa2ec7fcb980dcd2c7498dafe2f9ca2e52d735cf)), closes [#915](https://github.com/iamkun/dayjs/issues/915)
* Update Ukrainian (uk) locale monthFormat and monthStandalone ([#899](https://github.com/iamkun/dayjs/issues/899)) ([a08756e](https://github.com/iamkun/dayjs/commit/a08756e80bd1d7126fca28c5ad9e382613fc86c4))

## [1.8.27](https://github.com/iamkun/dayjs/compare/v1.8.26...v1.8.27) (2020-05-14)


16 changes: 15 additions & 1 deletion src/locale/uk.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Ukrainian [uk]
import dayjs from 'dayjs'

const monthFormat = 'січня_лютого_березня_квітня_травня_червня_липня_серпня_вересня_жовтня_листопада_грудня'.split('_')
const monthStandalone = 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.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
@@ -23,12 +28,21 @@ function relativeTimeWithPlural(number, withoutSuffix, key) {
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 locale = {
name: 'uk',
weekdays: 'неділя_понеділок_вівторок_середа_четвер_п’ятниця_субота'.split('_'),
weekdaysShort: 'ндл_пнд_втр_срд_чтв_птн_сбт'.split('_'),
weekdaysMin: 'нд_пн_вт_ср_чт_пт_сб'.split('_'),
months: 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_'),
months,
monthsShort: 'сiч_лют_бер_квiт_трав_черв_лип_серп_вер_жовт_лист_груд'.split('_'),
weekStart: 1,
relativeTime: {
12 changes: 6 additions & 6 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
@@ -78,19 +78,19 @@ const expressions = {
MMM: [matchWord, function (input) {
const months = getLocalePart('months')
const monthsShort = getLocalePart('monthsShort')
const matchIndex = (monthsShort || months.map(_ => _.substr(0, 3))).indexOf(input)
if (matchIndex < 0) {
const matchIndex = (monthsShort || months.map(_ => _.substr(0, 3))).indexOf(input) + 1
if (matchIndex < 1) {
throw new Error()
}
this.month = (matchIndex + 1) % 12
this.month = (matchIndex % 12) || matchIndex
}],
MMMM: [matchWord, function (input) {
const months = getLocalePart('months')
const matchIndex = months.indexOf(input)
if (matchIndex < 0) {
const matchIndex = months.indexOf(input) + 1
if (matchIndex < 1) {
throw new Error()
}
this.month = (matchIndex + 1) % 12
this.month = (matchIndex % 12) || matchIndex
}],
Y: [matchSigned, addInput('year')],
YY: [match2, function (input) {
13 changes: 13 additions & 0 deletions test/locale/uk.test.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,19 @@ afterEach(() => {
MockDate.reset()
})

it('Format Month with locale function', () => {
for (let i = 0; i <= 7; i += 1) {
const dayjsUK = dayjs().locale('uk').add(i, 'day')
const momentUK = moment().locale('uk').add(i, 'day')
const testFormat1 = 'DD MMMM YYYY MMM'
const testFormat2 = 'MMMM'
const testFormat3 = 'MMM'
expect(dayjsUK.format(testFormat1)).toEqual(momentUK.format(testFormat1))
expect(dayjsUK.format(testFormat2)).toEqual(momentUK.format(testFormat2))
expect(dayjsUK.format(testFormat3)).toEqual(momentUK.format(testFormat3))
}
})

it('RelativeTime: Time from X', () => {
const T = [
[44.4, 'second'], // a few seconds
6 changes: 6 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@ it('parse string for MMM month format', () => {
const input = '4/Mar/2019:11:16:26 +0800'
const format = 'D/MMM/YYYY:H:m:s zz'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
const input2 = '21-Dec-18'
const format2 = 'D-MMM-YY'
expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf())
})

it('parse string January (getMonth() = 0)', () => {
@@ -135,6 +138,9 @@ it('parse month from string', () => {
const input = '2018 February 03'
const format = 'YYYY MMMM DD'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
const input2 = '21-December-18'
const format2 = 'D-MMMM-YY'
expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf())
})

it('parse month from short string', () => {