Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain more clearly that days of the month are not padded by default #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) <sup>1</sup>
* `Do` - Day (8th)
* `h` - Hours - 12h format <sup>1</sup>
* `H` - Hours - 24h format <sup>1</sup>
* `mm` - Minutes (zero padded)
* `ss` - Seconds (zero padded)
* `a` - AM/PM

<sup>1</sup> - you get padded months (`09` instead of `9`) by passing in the `padMonth` option.
<sup>1</sup> - you get padded values (e.g. `09` instead of `9`) by passing the following options:
* `padHours` for hours
* `padDays` 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
```


Expand Down
20 changes: 14 additions & 6 deletions __test__/index.spec.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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', () => {
Expand Down