|
7 | 7 | MILLISECONDS_IN_DAY = 86400000, |
8 | 8 | MILLISECONDS_IN_HOUR = 3600000, |
9 | 9 | MILLISECONDS_IN_MINUTE = 60000, |
10 | | - token = /d{1,4}|M{1,4}|m{1,2}|w{1,2}|D{1,4}|YY(?:YY)?|H{1,2}|h{1,2}|s{1,2}|S{1,3}|Z{1,2}|a{1,2}|[AQExX]/g |
| 10 | + token = /d{1,4}|M{1,4}|m{1,2}|w{1,2}|Qo|Do|D{1,4}|YY(?:YY)?|H{1,2}|h{1,2}|s{1,2}|S{1,3}|Z{1,2}|a{1,2}|[AQExX]/g |
11 | 11 |
|
12 | 12 | export const dayNames = [ |
13 | 13 | 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' |
@@ -297,6 +297,18 @@ export function daysInMonth (date) { |
297 | 297 | return (new Date(date.getFullYear(), date.getMonth() + 1, 0)).getDate() |
298 | 298 | } |
299 | 299 |
|
| 300 | +function getOrdinal (n) { |
| 301 | + if (n >= 11 && n <= 13) { |
| 302 | + return `${n}th` |
| 303 | + } |
| 304 | + switch (n % 10) { |
| 305 | + case 1: return `${n}st` |
| 306 | + case 2: return `${n}nd` |
| 307 | + case 3: return `${n}rd` |
| 308 | + } |
| 309 | + return `${n}th` |
| 310 | +} |
| 311 | + |
300 | 312 | export const formatter = { |
301 | 313 | // Year: 00, 01, ..., 99 |
302 | 314 | YY (date) { |
@@ -333,11 +345,21 @@ export const formatter = { |
333 | 345 | return Math.ceil((date.getMonth() + 1) / 3) |
334 | 346 | }, |
335 | 347 |
|
| 348 | + // Quarter: 1st, 2nd, 3rd, 4th |
| 349 | + Qo (date) { |
| 350 | + return getOrdinal(this.Q(date)) |
| 351 | + }, |
| 352 | + |
336 | 353 | // Day of month: 1, 2, ..., 31 |
337 | 354 | D (date) { |
338 | 355 | return date.getDate() |
339 | 356 | }, |
340 | 357 |
|
| 358 | + // Day of month: 1st, 2nd, ..., 31st |
| 359 | + Do (date) { |
| 360 | + return getOrdinal(date.getDate()) |
| 361 | + }, |
| 362 | + |
341 | 363 | // Day of month: 01, 02, ..., 31 |
342 | 364 | DD (date) { |
343 | 365 | return pad(date.getDate()) |
|
0 commit comments