Skip to content

Commit

Permalink
Remove 00 like default second value (adamgibbons#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
diazdavid-info authored Feb 5, 2023
1 parent f0d0233 commit 80f3118
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/utils/format-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function formatDate(args = [], outputType = 'utc', inputType = 'l
return `${year}${pad(month)}${pad(date)}`
}

let outDate = new Date(new Date().setUTCSeconds(0, 0))
let outDate = new Date()
if (Array.isArray(args) && args.length > 0 && args[0]) {
const [year, month, date, hours = 0, minutes = 0, seconds = 0] = args
if (inputType === 'local') {
Expand Down
8 changes: 4 additions & 4 deletions test/utils/format-date.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { expect } from 'chai'

describe('utils.formatDate', () => {
it('defaults to local time input and UTC time output when no type passed', () => {
const now = dayjs(new Date(2017, 7-1, 16, 22, 30)).utc().format('YYYYMMDDTHHmm00')
expect(formatDate([2017, 7, 16, 22, 30])).to.equal(now+'Z')
const now = dayjs(new Date(2017, 7-1, 16, 22, 30, 35)).utc().format('YYYYMMDDTHHmmss')
expect(formatDate([2017, 7, 16, 22, 30, 35])).to.equal(now+'Z')
})
it('sets a local (i.e. floating) time when specified', () => {
expect(formatDate([1998, 6, 18, 23, 0], 'local', 'local')).to.equal('19980618T230000')
Expand All @@ -18,15 +18,15 @@ describe('utils.formatDate', () => {
expect(formatDate([2018, 2, 11])).to.equal('20180211')
})
it('defaults to NOW in UTC date-time when no args passed', () => {
const now = dayjs().utc().format('YYYYMMDDTHHmm00') + 'Z'
const now = dayjs().utc().format('YYYYMMDDTHHmmss') + 'Z'
expect(formatDate(undefined, 'utc')).to.equal(now)
})
it('sets a UTC date-time when passed well-formed args', () => {
expect(formatDate([2017, 9, 25, 0, 30], 'utc', 'utc')).to.equal('20170925T003000Z')
expect(formatDate([2017, 1, 31], 'utc','utc')).to.equal('20170131')
})
it('sets a local DATE-TIME value to NOW when passed nothing', () => {
const now = dayjs().format('YYYYMMDDTHHmm00')
const now = dayjs().format('YYYYMMDDTHHmmss')
expect(formatDate(undefined, 'local', 'local')).to.equal(now)
})
it('sets a local DATE-TIME value when passed args', () => {
Expand Down

0 comments on commit 80f3118

Please sign in to comment.