Skip to content

Commit

Permalink
test: add utc plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed May 26, 2021
1 parent 0914706 commit f2a2ea6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ export const INVALID_DATE_STRING = 'Invalid Date'
// regex
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g

// used by plugins/utc
export const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g
export const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g
5 changes: 4 additions & 1 deletion src/plugin/utc/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { MILLISECONDS_A_MINUTE, MIN, REGEX_VALID_OFFSET_FORMAT, REGEX_OFFSET_HOURS_MINUTES_FORMAT } from '../../constant'
import { MILLISECONDS_A_MINUTE, MIN } from '../../constant'

const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g
const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g

function offsetFromString(value = '') {
const offset = value.match(REGEX_VALID_OFFSET_FORMAT)
Expand Down
10 changes: 10 additions & 0 deletions test/plugin/utc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ describe('UTC Offset', () => {
expect(daysJS.utcOffset()).toEqual(0)
expect(daysJS.utcOffset()).toEqual(momentJS.utcOffset())
})

it('get utc offset with an invalid string value, value: 0', () => {
const time = '2021-02-28 19:40:10'
const daysJS = dayjs(time, { utc: true }).utc(true).utcOffset('+0000')
const momentJS = moment(time).utc(true).utcOffset('+0000')

expect(daysJS.toISOString()).toEqual(momentJS.toISOString())
expect(daysJS.utcOffset()).toEqual(0)
expect(daysJS.utcOffset()).toEqual(momentJS.utcOffset())
})
})

describe('Diff', () => {
Expand Down

0 comments on commit f2a2ea6

Please sign in to comment.