Skip to content

Commit

Permalink
Format seconds (adamgibbons#141)
Browse files Browse the repository at this point in the history
* more seconds formatting
* clean up tests
  • Loading branch information
adamgibbons authored Jun 7, 2020
1 parent 4a06843 commit b8bdc83
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/utils/format-local-date-as-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import moment from 'moment'
export default function formatLocalDateAsLocal(args = []) {
if (args.length > 0) {
const [year, month, date, hours = 0, minutes = 0, seconds = 0] = args
const formattedDate = moment([year, month - 1, date, hours, minutes, seconds]).format('YYYYMMDDTHHmm00')
const formattedDate = moment([year, month - 1, date, hours, minutes, seconds]).format('YYYYMMDDTHHmmss')
return formattedDate
}

return moment().format('YYYYMMDDTHHmm00')
return moment().format('YYYYMMDDTHHmmss')
}
4 changes: 2 additions & 2 deletions src/utils/format-local-date-as-utc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export default function formatLocalDateAsUTC(args = []) {
hours,
minutes,
seconds
]).utc().format('YYYYMMDDTHHmm00') + 'Z'
]).utc().format('YYYYMMDDTHHmmss') + 'Z'

return formattedDate
}

return moment.utc().format('YYYYMMDDTHHmm00') + 'Z'
return moment.utc().format('YYYYMMDDTHHmmss') + 'Z'
}
4 changes: 2 additions & 2 deletions src/utils/format-utc-date-as-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import moment from 'moment'
export default function formatLocalDateAsLocal(args = []) {
if (args.length > 0) {
const [year, month, date, hours = 0, minutes = 0, seconds = 0] = args
const formattedDate = moment.utc([year, month - 1, date, hours, minutes, seconds]).format('YYYYMMDDTHHmm00')
const formattedDate = moment.utc([year, month - 1, date, hours, minutes, seconds]).format('YYYYMMDDTHHmmss')
return formattedDate
}

return moment().utc().format('YYYYMMDDTHHmm00')
return moment().utc().format('YYYYMMDDTHHmmss')
}
13 changes: 9 additions & 4 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ describe('ics', () => {
expect(event1.value).to.be.a('string')
expect(event2.error).to.exist
})

it('returns an error when passed an empty object', (done) => {
createEvent({}, (error, success) => {
done()
expect(error.name).to.equal('ValidationError')
expect(success).not.to.exist
})
})

it('returns a node-style callback', (done) => {
createEvent(validAttributes, (error, success) => {
done()
expect(error).not.to.exist
expect(success).to.contain('DTSTART:200010')
})
})
it('returns unique uid\'s for multiple calls', () => {

it('returns UUIDs for multiple calls', () => {
const event1 = createEvent(validAttributes);
const event2 = createEvent(validAttributes2);

Expand All @@ -47,9 +50,9 @@ describe('ics', () => {
const events = createEvents()
expect(events.error).to.exist
})

it('writes begin and end calendar tags', () => {
const { error, value } = createEvents([validAttributes])
console.log(error, value)
expect(error).to.be.null
expect(value).to.contain('BEGIN:VCALENDAR')
expect(value).to.contain('END:VCALENDAR')
Expand All @@ -67,19 +70,21 @@ describe('ics', () => {
expect(value).not.to.exist
})
})

describe('when a callback is provided', () => {
it('returns an iCal string as the second argument when passed valid events', (done) => {
createEvents([validAttributes, validAttributes2, validAttributes3], (error, success) => {
done()
expect(error).not.to.exist
expect(success).to.contain('BEGIN:VCALENDAR')
done()
})
})

it('returns an error when passed an invalid event', (done) => {
createEvents([validAttributes, validAttributes2, invalidAttributes], (error, success) => {
done()
expect(error).to.exist
expect(success).not.to.exist
done()
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/utils/format-local-date-as-local.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ describe('utils.formatLocalDateAsLocal', () => {
expect(formatLocalDateAsLocal).to.exist
})
it('sets a DATE-TIME value to NOW when passed nothing', () => {
const now = moment().format('YYYYMMDDTHHmm00')
const now = moment().format('YYYYMMDDTHHmmss')
expect(formatLocalDateAsLocal()).to.equal(now)
})
it('sets a DATE-TIME value when passed args', () => {
expect(formatLocalDateAsLocal([1998, 1, 18, 23, 0]))
.to.equal('19980118T230000')
expect(formatLocalDateAsLocal([1998, 1, 18, 23, 9, 59]))
.to.equal('19980118T230959')
})
})

0 comments on commit b8bdc83

Please sign in to comment.