From b8bdc8301cdedf7584d67fbb9ec7aa6393488185 Mon Sep 17 00:00:00 2001 From: Adam Gibbons Date: Sat, 6 Jun 2020 23:50:15 -0600 Subject: [PATCH] Format seconds (#141) * more seconds formatting * clean up tests --- src/utils/format-local-date-as-local.js | 4 ++-- src/utils/format-local-date-as-utc.js | 4 ++-- src/utils/format-utc-date-as-local.js | 4 ++-- test/index.spec.js | 13 +++++++++---- test/utils/format-local-date-as-local.spec.js | 6 +++--- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/utils/format-local-date-as-local.js b/src/utils/format-local-date-as-local.js index 1b7b0e4..6524696 100644 --- a/src/utils/format-local-date-as-local.js +++ b/src/utils/format-local-date-as-local.js @@ -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') } diff --git a/src/utils/format-local-date-as-utc.js b/src/utils/format-local-date-as-utc.js index b221d17..24e967f 100644 --- a/src/utils/format-local-date-as-utc.js +++ b/src/utils/format-local-date-as-utc.js @@ -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' } diff --git a/src/utils/format-utc-date-as-local.js b/src/utils/format-utc-date-as-local.js index 14e36f6..f7b3bce 100644 --- a/src/utils/format-utc-date-as-local.js +++ b/src/utils/format-utc-date-as-local.js @@ -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') } diff --git a/test/index.spec.js b/test/index.spec.js index cda6967..f061058 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -16,6 +16,7 @@ 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() @@ -23,6 +24,7 @@ describe('ics', () => { expect(success).not.to.exist }) }) + it('returns a node-style callback', (done) => { createEvent(validAttributes, (error, success) => { done() @@ -30,7 +32,8 @@ describe('ics', () => { 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); @@ -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') @@ -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() }) }) }) diff --git a/test/utils/format-local-date-as-local.spec.js b/test/utils/format-local-date-as-local.spec.js index bf3d753..659d3a5 100644 --- a/test/utils/format-local-date-as-local.spec.js +++ b/test/utils/format-local-date-as-local.spec.js @@ -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') }) })