ization plugin for date/time formatting of various
Temporal
objects
Install ization system using Angular CLI (installs ization core and lets you pick ization plugins you want to install, then automatically adds ization code into your project):
npx ng add @ization/core
Alternatively, you can use your favourite package manager. If you use one that installs peer dependencies automatically (e.g. npm ≥7), you can simply install this package together with core package (and any other ization packages you want):
npm install @ization/core @ization/temporal
Otherwise, you need to install peer dependencies yourself (e.g. npm ≤6) in addition to installing this package. Don't forget to have a look at Readmes of other packages you are going to install as well. Output of npm install
can help you manage your peer dependencies.
npm install @ization/core @ization/temporal @js-temporal/polyfill lodash
If you want to be safe, use the same version for all ization packages. But if needed, ization follows semver so it is also possible to run different versions of packages:
@ization/temporal |
@ization/core |
Angular | @js-temporal/polyfill |
---|---|---|---|
2 | 1 - 2 | >= 11 | >= 0.2 |
1 | 2 | >= 11 | 0.1 |
Installing ization using Angular CLI automatically adds default configuration code into your project so you can start right away.
If you do not use Angular CLI: Configure @ization/core
first. Then, you need to add Temporal
polyfill to your project - unless you live in the bright future where Temporal is already shipped in browsers, then congratulations! One such polyfill is conveniently packaged with this plugin. Simply import it into your polyfills.ts
file:
import '@ization/temporal/polyfill';
Then, import the main module of this plugin into your app module using IzTemporalModule
:
@NgModule({
imports: [
...
IzTemporalModule,
...
],
...
})
export class AppModule {}
Optionally, you can provide your own formats for each pipe. To do that, import this plugin using IzTemporalModule.withCustomFormats
static method instead:
@NgModule({
imports: [
...
IzTemporalModule.withCustomFormats(myFormats),
...
],
...
})
export class AppModule {}
You can override locale code used by this plugin in IzCoreModule.withLocales
object via temporalLocaleCode
property.
temporalObj | izDate: format
temporalObj
-Temporal.PlainDate
orTemporal.PlainDateTime
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toDateFormatOptions
interface.
Returns string that represents the input localized as a date. Until @ization/core
is initialized, returns empty string.
temporalObj | izZonedDate: format
temporalObj
-Temporal.ZonedDateTime
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toDateFormatOptions
interface.
Returns string that represents the input localized as a date in provided time zone. Until @ization/core
is initialized, returns empty string.
temporalObj | IzLocalDatePipe: format
temporalObj
-Temporal.ZonedDateTime
orTemporal.Instant
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toDateFormatOptions
interface.
Returns string that represents the input localized as a date converted to local time zone. Until @ization/core
is initialized, returns empty string.
temporalObj | izTime: format
temporalObj
-Temporal.PlainTime
orTemporal.PlainDateTime
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toTimeFormatOptions
interface.
Returns string that represents the input localized as a time. Until @ization/core
is initialized, returns empty string.
temporalObj | izZonedTime: format
temporalObj
-Temporal.ZonedDateTime
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long' | 'zonedShort' | 'zonedMedium' | 'zonedLong'
or an object conforming toZonedTimeFormatOptions
interface.
Returns string that represents the input localized as a time in provided time zone. Until @ization/core
is initialized, returns empty string.
temporalObj | IzLocalTimePipe: format
temporalObj
-Temporal.ZonedDateTime
orTemporal.Instant
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long' | 'zonedShort' | 'zonedMedium' | 'zonedLong'
or an object conforming toZonedTimeFormatOptions
interface.
Returns string that represents the input localized as a time converted to local time zone. Until @ization/core
is initialized, returns empty string.
temporalObj | izDateTime: format
temporalObj
-Temporal.PlainDateTime
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toDateTimeFormatOptions
interface.
Returns string that represents the input localized as a date & time. Until @ization/core
is initialized, returns empty string.
temporalObj | izZonedDateTime: format
temporalObj
-Temporal.ZonedDateTime
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long' | 'zonedShort' | 'zonedMedium' | 'zonedLong'
or an object conforming toZonedDateTimeFormatOptions
interface.
Returns string that represents the input localized as a date & time in provided time zone. Until @ization/core
is initialized, returns empty string.
temporalObj | IzLocalDateTimePipe: format
temporalObj
-Temporal.ZonedDateTime
orTemporal.Instant
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long' | 'zonedShort' | 'zonedMedium' | 'zonedLong'
or an object conforming toZonedDateTimeFormatOptions
interface.
Returns string that represents the input localized as a date & time converted to local time zone. Until @ization/core
is initialized, returns empty string.
temporalObj | izYearMonth: format
temporalObj
-Temporal.PlainDate
,Temporal.PlainDateTime
, orTemporal.PlainYearMonth
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toYearMonthFormatOptions
interface.
Returns string that represents the input localized as a year & month. Until @ization/core
is initialized, returns empty string.
temporalObj | izMonthDay: format
temporalObj
-Temporal.PlainDate
,Temporal.PlainDateTime
, orTemporal.PlainMonthDay
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toMonthDayFormatOptions
interface.
Returns string that represents the input localized as a month & day. Until @ization/core
is initialized, returns empty string.
temporalObj | izWeekday: format
temporalObj
-Temporal.PlainDate
orTemporal.PlainDateTime
instance to localize.format
- Format to use. Can be either one of strings'short' | 'medium' | 'long'
or an object conforming toWeekdayFormatOptions
interface.
Returns string that represents the input localized as a weekday. Until @ization/core
is initialized, returns empty string.
Run npm run build:temporal
to build the package into the dist/temporal/
directory.
Run npm run test:temporal
to execute the unit tests.
Run npm run lint:temporal
to run linter on all code, including spec files.
This library is licensed under Parity 7.0.0 license. If you want to use this library in open source projects, go ahead, it's completely free! If you'd rather keep your code closed, you have 30 days to try the library in your project, then you need to buy a private license. Have a look at GitHub Sponsors or contact me directly at get@ization.dev to negotiate a deal.