Skip to content

Commit

Permalink
final tweaks for v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesHoppe committed Dec 2, 2020
1 parent 8e5a2de commit 137d709
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 12 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ http://johanneshoppe.github.io/angular-date-value-accessor/
You have to explicitly opt-in by adding the attribute `useValueAsDate` to a date input control:

```html
<!-- DateValueAccessor (UTC) --->

<input type="date"
name="myBirthday"
ngModel
Expand All @@ -40,14 +42,35 @@ OR
<input type="date"
formControlName="myBirthday"
useValueAsDate>

<!-- LocalDateValueAccessor (Local Time) --->

<input type="date"
name="myBirthday"
ngModel
useValueAsLocalDate>

OR

<input type="date"
name="myBirthday"
[(ngModel)]="myBirthday"
useValueAsLocalDate>

OR

<input type="date"
formControlName="myBirthday"
useValueAsLocalDate>

```

## Installation

Download the package via NPM:

```bash
npm install --save angular-date-value-accessor
npm install angular-date-value-accessor
```

## UTC Time and Local Time
Expand All @@ -63,6 +86,7 @@ Depending on the requirements of your application you can choose the from these


## DateValueAccessor (UTC)

The DateValueAccessor operates in UTC (Coordinated Universal Time).
The HTML date input will read the UTC representation of the Date Object. When you select a date it will output an UTC date with the time set to 00:00 (UTC).

Expand All @@ -89,9 +113,7 @@ If you prefer to work with Local Dates then you can use the `LocalDateValueAcces

The HTML date input will read the Local Time representation of the Date Object. When you select a date it will output a Local Date with the time set to 00:00 (Local Time).

Most UI component libraries like Angular Material, Kendo Angular, PrimeNG implement their DatePickers operating in Local Time.

Also the Angular Date Pipe uses the Local Time representation of the Date Object by default.
Import the module via NgModule:

```js
// app.module.ts
Expand All @@ -108,6 +130,7 @@ export class AppModule { }

Now you can apply the `useValueAsLocalDate` to your date input controls.

> **ℹ️ Hint:** Most UI component libraries like Angular Material, Kendo Angular, PrimeNG implement their DatePickers operating in Local Time. The Angular Date Pipe uses the Local Time representation of the Date Object by default, too.
[npm-url]: https://npmjs.org/package/angular-date-value-accessor
[npm-image]: https://badge.fury.io/js/angular-date-value-accessor.svg
Expand Down
72 changes: 69 additions & 3 deletions workspace/projects/date-value-accessor/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# DateValueAccessor for Angular
[![NPM version][npm-image]][npm-url]
[![Tests][tests-image]][tests-url]

A custom value accessor for Angular.
Now you can use `<input type="date">` (provides real JavaScript date objects) directly with two-way data bindings (ngModel) as well as with reactive forms (formControlName/formControl).
Expand All @@ -22,6 +23,8 @@ http://johanneshoppe.github.io/angular-date-value-accessor/
You have to explicitly opt-in by adding the attribute `useValueAsDate` to a date input control:

```html
<!-- DateValueAccessor (UTC) --->

<input type="date"
name="myBirthday"
ngModel
Expand All @@ -39,17 +42,55 @@ OR
<input type="date"
formControlName="myBirthday"
useValueAsDate>

<!-- LocalDateValueAccessor (Local Time) --->

<input type="date"
name="myBirthday"
ngModel
useValueAsLocalDate>

OR

<input type="date"
name="myBirthday"
[(ngModel)]="myBirthday"
useValueAsLocalDate>

OR

<input type="date"
formControlName="myBirthday"
useValueAsLocalDate>

```

## Installation

Download the package via NPM:

```bash
npm install --save angular-date-value-accessor
npm install angular-date-value-accessor
```

Then import the module via NgModule:
## UTC Time and Local Time
When working with Dates in Javascript you either operate in UTC or Local Time.

* UTC is has no timezone offset.
* Local Time depends on the host system time zone and offset.

Javascript Dates support both the UTC and the Local Time representation.
Depending on the requirements of your application you can choose the from these Value Accessors:
* [DateValueAccessor (UTC)](#datevalueaccessor-utc)
* [LocalDateValueAccessor (Local Time)](#localdatevalueaccessor-local-time)


## DateValueAccessor (UTC)

The DateValueAccessor operates in UTC (Coordinated Universal Time).
The HTML date input will read the UTC representation of the Date Object. When you select a date it will output an UTC date with the time set to 00:00 (UTC).

Import the module via NgModule:

```js
// app.module.ts
Expand All @@ -64,9 +105,34 @@ import { DateValueAccessorModule } from 'angular-date-value-accessor';
export class AppModule { }
```

Now you can apply the "useValueAsDate" to your date input controls.
Now you can apply the `useValueAsDate` to your date input controls.

## LocalDateValueAccessor (Local Time)

If you prefer to work with Local Dates then you can use the `LocalDateValueAccessorModule`.

The HTML date input will read the Local Time representation of the Date Object. When you select a date it will output a Local Date with the time set to 00:00 (Local Time).

Import the module via NgModule:

```js
// app.module.ts

import { LocalDateValueAccessorModule } from 'angular-date-value-accessor';

@NgModule({
imports: [
LocalDateValueAccessorModule
]
})
export class AppModule { }
```

Now you can apply the `useValueAsLocalDate` to your date input controls.

> **ℹ️ Hint:** Most UI component libraries like Angular Material, Kendo Angular, PrimeNG implement their DatePickers operating in Local Time. The Angular Date Pipe uses the Local Time representation of the Date Object by default, too.
[npm-url]: https://npmjs.org/package/angular-date-value-accessor
[npm-image]: https://badge.fury.io/js/angular-date-value-accessor.svg
[tests-url]: https://github.com/JohannesHoppe/angular-date-value-accessor/actions?query=workflow%3ATests
[tests-image]: https://github.com/JohannesHoppe/angular-date-value-accessor/workflows/Tests/badge.svg
13 changes: 8 additions & 5 deletions workspace/projects/date-value-accessor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-date-value-accessor",
"version": "1.1.0",
"description": "DateValueAccessor for Angular. Now you can use <input type='date'> with template-driven and reactive forms!",
"version": "1.2.0",
"description": "DateValueAccessor / LocalDateValueAccessor for Angular. Now you can use <input type='date'> with template-driven and reactive forms!",
"repository": {
"type": "git",
"url": "git+https://github.com/johanneshoppe/angular-date-value-accessor.git"
Expand All @@ -10,7 +10,10 @@
"angular",
"forms",
"ControlValueAccessor",
"DateValueAccessor"
"DateValueAccessor",
"LocalDateValueAccessor",
"UTC",
"Local Time"
],
"author": {
"name": "Johannes Hoppe",
Expand All @@ -23,8 +26,8 @@
},
"homepage": "https://github.com/johanneshoppe/angular-date-value-accessor",
"peerDependencies": {
"@angular/common": "^9.0.0 || ^10.0.0",
"@angular/core": "^9.0.0 || ^10.0.0"
"@angular/common": "^9.0.0 || ^10.0.0 || ^11.0.0",
"@angular/core": "^9.0.0 || ^10.0.0 || ^11.0.0"
},
"dependencies": {
"tslib": "^2.0.0"
Expand Down

0 comments on commit 137d709

Please sign in to comment.