Skip to content

Commit cbc04e5

Browse files
committed
Fixed custom date format regexp (missing support for AM/PM) (#75)
1 parent 92276b3 commit cbc04e5

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

src/app/pages/settings/datetime-format-editor/datetime-format-editor.component.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ <h4>Custom format</h4>
8585
mm Minutes, 2-digits
8686
s Seconds
8787
ss Seconds, 2-digits
88-
Z Offset from UTC
89-
ZZ Compact offset from UTC, 2-digits
9088
A Post or ante meridiem, upper-case
9189
a Post or ante meridiem, lower-case
9290
</pre>

src/app/pipes/datetime.pipe.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ export class DatetimePipe implements PipeTransform {
5353
* mm 00-59 Minutes, 2-digits
5454
* s 0-59 Seconds
5555
* ss 00-59 Seconds, 2-digits
56-
* Z -05:00 Offset from UTC
57-
* ZZ -0500 Compact offset from UTC, 2-digits
5856
* A AM PM Post or ante meridiem, upper-case
5957
* a am pm Post or ante meridiem, lower-case
6058
*/
6159
private static toCustomFormat(timestamp: Date|number, format: string = DEFAULT_DATE_FORMAT): string {
6260

6361
const date = typeof timestamp === 'number' ? new Date(timestamp) : timestamp;
6462

65-
return format.replaceAll(/(?<!\\)([YMDHhms])\1{0,3}/gm, (match: string) => {
63+
return format.replaceAll(/(YYYY|YY|MMMM|MMM|MM|M|DDDD|DDD|DD|D|HH|H|hh|h|mm|m|ss|s|A|a)/gm, (match: string) => {
6664

6765
switch (match) {
6866
// year

0 commit comments

Comments
 (0)