diff --git a/README.md b/README.md index 8e4eede..1b46976 100644 --- a/README.md +++ b/README.md @@ -258,8 +258,8 @@ Works with Angular’s [`DatePipe`][angular-datepipe]: Transforms a DateTime into a relative time: ``` -{{ date | dateTimeToRelative:'day':'long' }} -{{ date | dateTimeToRelativeCalendar:'month' }} +{{ date | dateTimeToRelative:{ unit: 'day', style: 'long' } }} +{{ date | dateTimeToRelativeCalendar:{ unit: 'month' } }} ``` The unit and style parameters are optional. diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-format.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-format.pipe.ts index e45f408..2310b63 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-format.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-format.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, LocaleOptions } from 'luxon'; @Pipe({ name: 'dateTimeToFormat' }) export class DateTimeToFormatPipe implements PipeTransform { - transform (value: T, format: string) { - return (value == null ? null : value.toFormat(format)) as T extends DateTime ? string : null; + transform (value: T, format: string, opts?: LocaleOptions) { + return (value == null ? null : value.toFormat(format, opts)) as T extends DateTime ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-iso-date.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-iso-date.pipe.ts index cd77748..fd5c03d 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-iso-date.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-iso-date.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, ToISODateOptions } from 'luxon'; @Pipe({ name: 'dateTimeToIsoDate' }) export class DateTimeToIsoDatePipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : value.toISODate()) as T extends DateTime ? string : null; + transform (value: T, opts?: ToISODateOptions) { + return (value == null ? null : value.toISODate(opts)) as T extends DateTime ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-iso-time.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-iso-time.pipe.ts index 5afd8c6..93de41e 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-iso-time.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-iso-time.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, ToISOTimeOptions } from 'luxon'; @Pipe({ name: 'dateTimeToIsoTime' }) export class DateTimeToIsoTimePipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : value.toISOTime()) as T extends DateTime ? string : null; + transform (value: T, opts?: ToISOTimeOptions) { + return (value == null ? null : value.toISOTime(opts)) as T extends DateTime ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-iso.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-iso.pipe.ts index 4d3a760..42487ec 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-iso.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-iso.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, ToISOTimeOptions } from 'luxon'; @Pipe({ name: 'dateTimeToIso' }) export class DateTimeToIsoPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : value.toISO()) as T extends DateTime ? string : null; + transform (value: T, opts?: ToISOTimeOptions) { + return (value == null ? null : value.toISO(opts)) as T extends DateTime ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-locale-string.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-locale-string.pipe.ts index 0a6b3c1..e5fed70 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-locale-string.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-locale-string.pipe.ts @@ -5,12 +5,7 @@ import { DateTime, DateTimeFormatOptions, LocaleOptions } from 'luxon'; name: 'dateTimeToLocaleString' }) export class DateTimeToLocaleStringPipe implements PipeTransform { - transform( - value: T, - format?: DateTimeFormatOptions - ) { - return ( - value == null ? null : value.toLocaleString(format) - ) as T extends DateTime ? string : null; + transform(value: T, format?: DateTimeFormatOptions, opts?: LocaleOptions) { + return (value == null ? null : value.toLocaleString(format, opts)) as T extends DateTime ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-relative-calendar.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-relative-calendar.pipe.ts index d3c8beb..db073e7 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-relative-calendar.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-relative-calendar.pipe.ts @@ -1,5 +1,5 @@ import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core'; -import { DateTime, ToRelativeUnit } from 'luxon'; +import { DateTime, ToRelativeCalendarOptions, ToRelativeUnit } from 'luxon'; import { Subscription, interval } from 'rxjs'; @Pipe({ @@ -18,7 +18,7 @@ export class DateTimeToRelativeCalendarPipe implements OnDestroy, PipeTransform } } - transform (value: T, unit?: ToRelativeUnit) { + transform (value: T, opts?: ToRelativeCalendarOptions) { if (value == null) { if (this.subscription) { this.subscription.unsubscribe(); @@ -32,8 +32,6 @@ export class DateTimeToRelativeCalendarPipe implements OnDestroy, PipeTransform this.subscription = interval(1000).subscribe(() => this.ref.markForCheck()); } - return value.toRelativeCalendar({ - unit - }); + return value.toRelativeCalendar(opts); } } diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-relative.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-relative.pipe.ts index d47bddd..fbc0494 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-relative.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-relative.pipe.ts @@ -1,5 +1,5 @@ import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core'; -import { DateTime, ToRelativeUnit } from 'luxon'; +import { DateTime, ToRelativeOptions, ToRelativeUnit } from 'luxon'; import { Subscription, interval } from 'rxjs'; @Pipe({ @@ -18,7 +18,7 @@ export class DateTimeToRelativePipe implements OnDestroy, PipeTransform { } } - transform (value: T, unit?: ToRelativeUnit, style?: 'long' | 'short' | 'narrow') { + transform (value: T, opts?: ToRelativeOptions) { if (value == null) { if (this.subscription) { this.subscription.unsubscribe(); @@ -32,9 +32,6 @@ export class DateTimeToRelativePipe implements OnDestroy, PipeTransform { this.subscription = interval(1000).subscribe(() => this.ref.markForCheck()); } - return value.toRelative({ - style, - unit - }); + return value.toRelative(opts); } } diff --git a/projects/luxon-angular/src/lib/formatting/date-time-to-sql.pipe.ts b/projects/luxon-angular/src/lib/formatting/date-time-to-sql.pipe.ts index 8be03ab..36f6ac2 100644 --- a/projects/luxon-angular/src/lib/formatting/date-time-to-sql.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/date-time-to-sql.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, ToSQLOptions } from 'luxon'; @Pipe({ name: 'dateTimeToSql' }) export class DateTimeToSqlPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : value.toSQL()) as T extends DateTime ? string : null; + transform (value: T, opts?: ToSQLOptions) { + return (value == null ? null : value.toSQL(opts)) as T extends DateTime ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/duration-to-format.pipe.ts b/projects/luxon-angular/src/lib/formatting/duration-to-format.pipe.ts index 8694281..2a7d0cc 100644 --- a/projects/luxon-angular/src/lib/formatting/duration-to-format.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/duration-to-format.pipe.ts @@ -5,7 +5,7 @@ import { Duration } from 'luxon'; name: 'durationToFormat' }) export class DurationToFormatPipe implements PipeTransform { - transform (value: T, format: string) { - return (value == null ? null : value.toFormat(format)) as T extends Duration ? string : null; + transform (value: T, format: string, opts?: { floor?: boolean }) { + return (value == null ? null : value.toFormat(format, opts)) as T extends Duration ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/duration-to-human.pipe.ts b/projects/luxon-angular/src/lib/formatting/duration-to-human.pipe.ts index 55c0666..e0be377 100644 --- a/projects/luxon-angular/src/lib/formatting/duration-to-human.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/duration-to-human.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { Duration } from 'luxon'; +import { Duration, ToHumanDurationOptions } from 'luxon'; @Pipe({ name: 'durationToHuman' }) export class DurationToHumanPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : value.toHuman()) as T extends Duration ? string : null; + transform (value: T, opts?: ToHumanDurationOptions) { + return (value == null ? null : value.toHuman(opts)) as T extends Duration ? string : null; } } diff --git a/projects/luxon-angular/src/lib/formatting/duration-to-iso-time.pipe.ts b/projects/luxon-angular/src/lib/formatting/duration-to-iso-time.pipe.ts index cac4ac0..b0a2be9 100644 --- a/projects/luxon-angular/src/lib/formatting/duration-to-iso-time.pipe.ts +++ b/projects/luxon-angular/src/lib/formatting/duration-to-iso-time.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { Duration } from 'luxon'; +import { Duration, ToISOTimeDurationOptions } from 'luxon'; @Pipe({ name: 'durationToIsoTime' }) export class DurationToIsoTimePipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : value.toISOTime()) as T extends Duration ? string : null; + transform (value: T, opts?: ToISOTimeDurationOptions) { + return (value == null ? null : value.toISOTime(opts)) as T extends Duration ? string : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/date-time-from-format.pipe.ts b/projects/luxon-angular/src/lib/parsing/date-time-from-format.pipe.ts index 8e4a71f..db72905 100644 --- a/projects/luxon-angular/src/lib/parsing/date-time-from-format.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/date-time-from-format.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, DateTimeOptions } from 'luxon'; @Pipe({ name: 'dateTimeFromFormat' }) export class DateTimeFromFormatPipe implements PipeTransform { - transform (value: T, format: string) { - return (value == null ? null : DateTime.fromFormat(value as string, format)) as T extends string ? DateTime : null; + transform (value: T, format: string, opts?: DateTimeOptions) { + return (value == null ? null : DateTime.fromFormat(value as string, format, opts)) as T extends string ? DateTime : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/date-time-from-http.pipe.ts b/projects/luxon-angular/src/lib/parsing/date-time-from-http.pipe.ts index 9fca8d3..a72f7c1 100644 --- a/projects/luxon-angular/src/lib/parsing/date-time-from-http.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/date-time-from-http.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, DateTimeOptions } from 'luxon'; @Pipe({ name: 'dateTimeFromHttp' }) export class DateTimeFromHttpPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : DateTime.fromHTTP(value as string)) as T extends string ? DateTime : null; + transform (value: T, opts?: DateTimeOptions) { + return (value == null ? null : DateTime.fromHTTP(value as string, opts)) as T extends string ? DateTime : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/date-time-from-iso.pipe.ts b/projects/luxon-angular/src/lib/parsing/date-time-from-iso.pipe.ts index 3d9a92b..0c56614 100644 --- a/projects/luxon-angular/src/lib/parsing/date-time-from-iso.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/date-time-from-iso.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, DateTimeOptions } from 'luxon'; @Pipe({ name: 'dateTimeFromIso' }) export class DateTimeFromIsoPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : DateTime.fromISO(value as string)) as T extends string ? DateTime : null; + transform (value: T, opts?: DateTimeOptions) { + return (value == null ? null : DateTime.fromISO(value as string, opts)) as T extends string ? DateTime : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/date-time-from-js-date.pipe.ts b/projects/luxon-angular/src/lib/parsing/date-time-from-js-date.pipe.ts index 20b3c12..19ba3cd 100644 --- a/projects/luxon-angular/src/lib/parsing/date-time-from-js-date.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/date-time-from-js-date.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, Zone } from 'luxon'; @Pipe({ name: 'dateTimeFromJsDate' }) export class DateTimeFromJsDatePipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : DateTime.fromJSDate(value as Date)) as T extends Date ? DateTime : null; + transform (value: T, opts?: { zone?: string | Zone }) { + return (value == null ? null : DateTime.fromJSDate(value as Date, opts)) as T extends Date ? DateTime : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/date-time-from-milliseconds.pipe.ts b/projects/luxon-angular/src/lib/parsing/date-time-from-milliseconds.pipe.ts index c3fe0fe..1a73328 100644 --- a/projects/luxon-angular/src/lib/parsing/date-time-from-milliseconds.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/date-time-from-milliseconds.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, DateTimeJSOptions } from 'luxon'; @Pipe({ name: 'dateTimeFromMilliseconds' }) export class DateTimeFromMillisecondsPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : DateTime.fromMillis(value as number)) as T extends number ? DateTime : null; + transform (value: T, opts?: DateTimeJSOptions) { + return (value == null ? null : DateTime.fromMillis(value as number, opts)) as T extends number ? DateTime : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/date-time-from-rfc-2822.pipe.ts b/projects/luxon-angular/src/lib/parsing/date-time-from-rfc-2822.pipe.ts index f299272..850d3a3 100644 --- a/projects/luxon-angular/src/lib/parsing/date-time-from-rfc-2822.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/date-time-from-rfc-2822.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, DateTimeOptions } from 'luxon'; @Pipe({ name: 'dateTimeFromRfc2822' }) export class DateTimeFromRfc2822Pipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : DateTime.fromRFC2822(value as string)) as T extends string ? DateTime : null; + transform (value: T, opts?: DateTimeOptions) { + return (value == null ? null : DateTime.fromRFC2822(value as string, opts)) as T extends string ? DateTime : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/date-time-from-sql.pipe.ts b/projects/luxon-angular/src/lib/parsing/date-time-from-sql.pipe.ts index addbb53..3856a6b 100644 --- a/projects/luxon-angular/src/lib/parsing/date-time-from-sql.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/date-time-from-sql.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, DateTimeOptions } from 'luxon'; @Pipe({ name: 'dateTimeFromSql' }) export class DateTimeFromSqlPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : DateTime.fromSQL(value as string)) as T extends string ? DateTime : null; + transform (value: T, opts?: DateTimeOptions) { + return (value == null ? null : DateTime.fromSQL(value as string, opts)) as T extends string ? DateTime : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/duration-from-iso-time.pipe.ts b/projects/luxon-angular/src/lib/parsing/duration-from-iso-time.pipe.ts index bb77b21..18e782c 100644 --- a/projects/luxon-angular/src/lib/parsing/duration-from-iso-time.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/duration-from-iso-time.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { Duration } from 'luxon'; +import { Duration, DurationOptions } from 'luxon'; @Pipe({ name: 'durationFromIsoTime' }) export class DurationFromIsoTimePipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : Duration.fromISOTime(value as string)) as T extends string ? Duration : null; + transform (value: T, opts?: DurationOptions) { + return (value == null ? null : Duration.fromISOTime(value as string, opts)) as T extends string ? Duration : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/duration-from-iso.pipe.ts b/projects/luxon-angular/src/lib/parsing/duration-from-iso.pipe.ts index fde3e57..300a020 100644 --- a/projects/luxon-angular/src/lib/parsing/duration-from-iso.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/duration-from-iso.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { Duration } from 'luxon'; +import { Duration, DurationOptions } from 'luxon'; @Pipe({ name: 'durationFromIso' }) export class DurationFromIsoPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : Duration.fromISO(value as string)) as T extends string ? Duration : null; + transform (value: T, opts?: DurationOptions) { + return (value == null ? null : Duration.fromISO(value as string, opts)) as T extends string ? Duration : null; } } diff --git a/projects/luxon-angular/src/lib/parsing/duration-from-milliseconds.pipe.ts b/projects/luxon-angular/src/lib/parsing/duration-from-milliseconds.pipe.ts index 06d5185..ac726a3 100644 --- a/projects/luxon-angular/src/lib/parsing/duration-from-milliseconds.pipe.ts +++ b/projects/luxon-angular/src/lib/parsing/duration-from-milliseconds.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { Duration } from 'luxon'; +import { Duration, DurationOptions } from 'luxon'; @Pipe({ name: 'durationFromMilliseconds' }) export class DurationFromMillisecondsPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : Duration.fromMillis(value as number)) as T extends number ? Duration : null; + transform (value: T, opts?: DurationOptions) { + return (value == null ? null : Duration.fromMillis(value as number, opts)) as T extends number ? Duration : null; } } diff --git a/projects/luxon-angular/src/lib/zones/date-time-to-utc.pipe.ts b/projects/luxon-angular/src/lib/zones/date-time-to-utc.pipe.ts index 50f247e..36e9c8c 100644 --- a/projects/luxon-angular/src/lib/zones/date-time-to-utc.pipe.ts +++ b/projects/luxon-angular/src/lib/zones/date-time-to-utc.pipe.ts @@ -1,11 +1,11 @@ import { Pipe, PipeTransform } from '@angular/core'; -import { DateTime } from 'luxon'; +import { DateTime, ZoneOptions } from 'luxon'; @Pipe({ name: 'dateTimeToUtc' }) export class DateTimeToUtcPipe implements PipeTransform { - transform (value: T) { - return (value == null ? null : value.toUTC()) as T extends DateTime ? DateTime : null; + transform (value: T, offset?: number, opts?: ZoneOptions) { + return (value == null ? null : value.toUTC(offset, opts)) as T extends DateTime ? DateTime : null; } }