From f6b345a92e228b3460a57aeceb70ff3a96fe3c71 Mon Sep 17 00:00:00 2001 From: Sergio Regueira Date: Wed, 27 Jun 2018 23:19:00 +0200 Subject: [PATCH 1/3] Change the day of the month to explain clearly it is not padded by default --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 35c1fc1..feeecd0 100644 --- a/README.md +++ b/README.md @@ -28,18 +28,23 @@ template.render(new Date()); * `YYYY` - Full Year (1992) * `YY` - Partial Year (92) * `dddd` - Day of the Week (Monday) - * `DD` - Day of the Month (24) - * `Do` - Day (24th) - * `h` - Hours - 12h format - * `H` - Hours - 24h format + * `DD` - Day of the Month (8) 1 + * `Do` - Day (8th) + * `h` - Hours - 12h format 1 + * `H` - Hours - 24h format 1 * `mm` - Minutes (zero padded) * `ss` - Seconds (zero padded) * `a` - AM/PM - 1 - you get padded months (`09` instead of `9`) by passing in the `padMonth` option. + 1 - you get padded values (e.g. `09` instead of `9`) by passing the following options: + * `padMonth` for hours + * `padMonth` for days + * `padMonth` for months ```js - const template = tinytime('{Mo}', { padMonth: true }) + const opts = { padHours: true, padMonth: true, padDays: true}; + const template = tinytime('{YYYY}-{Mo}-{DD} {h}:{mm}:{ss}', opts); + // 1992-09-08 09:07:30 ``` From dcf95f044b05130d7fada6015d7a7fa1fa23e4b8 Mon Sep 17 00:00:00 2001 From: Sergio Regueira Date: Wed, 27 Jun 2018 23:24:07 +0200 Subject: [PATCH 2/3] Update unit tests to use a day of the month that requires one digit and test padDay option --- __test__/index.spec.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/__test__/index.spec.js b/__test__/index.spec.js index ed90c18..5086f16 100644 --- a/__test__/index.spec.js +++ b/__test__/index.spec.js @@ -1,7 +1,7 @@ import tinytime from '../src' // My birthday! -const date = new Date('September 24, 1992 021:07:30'); +const date = new Date('September 8, 1992 021:07:30'); // Helper function to render template with the same date. const render = template => tinytime(template).render(date) @@ -16,7 +16,7 @@ describe('tinytime', () => { }); describe('rendering', () => { it('should let you render with a date/time', () => { - expect(render('{h}:{mm}:{ss}{a} on a {dddd}.')).toEqual('9:07:30PM on a Thursday.'); + expect(render('{h}:{mm}:{ss}{a} on a {dddd}.')).toEqual('9:07:30PM on a Tuesday.'); }); it('full months', () => { expect(render('{MMMM}')).toEqual('September'); @@ -39,10 +39,18 @@ describe('tinytime', () => { expect(render('{YY}')).toEqual('92'); }) it('days of the week', () => { - expect(render('{dddd}')).toEqual('Thursday'); + expect(render('{dddd}')).toEqual('Tuesday'); }); - it('day of the month', () => { - expect(render('{Do}')).toEqual('24th'); + it('days of the month', () => { + expect(render('{DD}')).toEqual('8'); + }); + it('padded days of the month', () => { + const template = tinytime('{DD}', { padDays: true }); + const rendered = template.render(date); + expect(rendered).toEqual('08'); + }); + it('days', () => { + expect(render('{Do}')).toEqual('8th'); }); it('times', () => { expect(render('{h}:{mm}:{ss}{a}')).toEqual('9:07:30PM'); @@ -65,7 +73,7 @@ describe('tinytime', () => { expect(render( 'It was {h}:{mm}:{ss}{a} on {MMMM} {Do}, {YYYY}.' )).toEqual( - 'It was 9:07:30PM on September 24th, 1992.' + 'It was 9:07:30PM on September 8th, 1992.' ) }); it('sundays', () => { From 3a8f1676e219888cc4539be704f0ac039c1a4d3a Mon Sep 17 00:00:00 2001 From: Sergio Regueira Date: Wed, 27 Jun 2018 23:46:33 +0200 Subject: [PATCH 3/3] Fix typo in padding options --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index feeecd0..ac1d221 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ template.render(new Date()); * `a` - AM/PM 1 - you get padded values (e.g. `09` instead of `9`) by passing the following options: - * `padMonth` for hours - * `padMonth` for days + * `padHours` for hours + * `padDays` for days * `padMonth` for months ```js