diff --git a/README.md b/README.md index a8db1fd..aa8f853 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/__test__/index.spec.js b/__test__/index.spec.js index ed90c18..d24265c 100644 --- a/__test__/index.spec.js +++ b/__test__/index.spec.js @@ -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'); }); diff --git a/src/compiler.js b/src/compiler.js index 1227a1f..efea21f 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -15,6 +15,7 @@ PostOrAnteMeridiem, UserText, Day, DayOfTheMonth, +PartialDayOfTheWeek, } from './subs'; import type { Token } from './parser' import type { TinyTimeOptions } from './index' @@ -119,6 +120,9 @@ export default function compiler(tokens: Array, 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; diff --git a/src/subs.js b/src/subs.js index 2126686..05794dd 100644 --- a/src/subs.js +++ b/src/subs.js @@ -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 @@ -30,6 +31,7 @@ const SubToTypeIdentifierMap: { 'YYYY': FullYear, 'YY': PartialYear, 'dddd': DayOfTheWeek, + 'dd': PartialDayOfTheWeek, 'DD': DayOfTheMonth, 'Do': Day, 'h': Hour,