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

Support partial day of the week #44

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ template.render(new Date());
* `YYYY` - Full Year (1992)
* `YY` - Partial Year (92)
* `dddd` - Day of the Week (Monday)
* `dd` - Partial Day of the Week (Mon)
* `DD` - Day of the Month (24)
* `Do` - Day (24th)
* `h` - Hours - 12h format
Expand Down
3 changes: 3 additions & 0 deletions __test__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ describe('tinytime', () => {
it('days of the week', () => {
expect(render('{dddd}')).toEqual('Thursday');
});
it('partial day of the week', () => {
expect(render('{dd}')).toEqual('Thu');
});
it('day of the month', () => {
expect(render('{Do}')).toEqual('24th');
});
Expand Down
4 changes: 4 additions & 0 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ PostOrAnteMeridiem,
UserText,
Day,
DayOfTheMonth,
PartialDayOfTheWeek,
} from './subs';
import type { Token } from './parser'
import type { TinyTimeOptions } from './index'
Expand Down Expand Up @@ -119,6 +120,9 @@ export default function compiler(tokens: Array<Token>, date: Date, options: Tiny
case PartialYear:
compiled += (year + '').slice(2);
break;
case PartialDayOfTheWeek:
compiled += days[date.getDay()].slice(0, 3);
break;
case DayOfTheWeek:
compiled += days[date.getDay()];
break;
Expand Down
2 changes: 2 additions & 0 deletions src/subs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const Day = 'k';
export const DayOfTheMonth = 'l';
export const NumberMonth = 'n';
export const Hour24 = 'm';
export const PartialDayOfTheWeek = 'o';

const SubToTypeIdentifierMap: {
[abbreviation: string]: string
Expand All @@ -30,6 +31,7 @@ const SubToTypeIdentifierMap: {
'YYYY': FullYear,
'YY': PartialYear,
'dddd': DayOfTheWeek,
'dd': PartialDayOfTheWeek,
'DD': DayOfTheMonth,
'Do': Day,
'h': Hour,
Expand Down