From 844c8c44884a647bad9bf3e03ee121d214c06f24 Mon Sep 17 00:00:00 2001 From: Daniel Luz Date: Mon, 21 Aug 2017 01:10:55 -0300 Subject: [PATCH] Fix timezone in serialized dates BREAKING CHANGE: this affects the server-side parsing of dates sent by this library. Previously, the server had to completely ignore the timezone information ("UTC"), then treat the date as local. Now the front-end will properly send the local date plus the local timezone, which allows the back-end to reliably choose between either handling it as a local time, or convert it to some other timezone, like UTC. --- README.MD | 4 ++-- src/decorators/attribute.decorator.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.MD b/README.MD index 5bdbab04..689be72a 100644 --- a/README.MD +++ b/README.MD @@ -445,8 +445,8 @@ export class Post extends JsonApiModel { ``` Moreover, it should be noted that the following assumptions have been made: -- The JsonApi spec suggests that ISO8601 format is used for dates, the code assumes the producer of the Api has followed this suggestion -- The library also assumes that dates will be sent and received in UTC. This should be a safe assumption for Api providers to multinational clients, or cloud hosting where the timezone of the server cannot be guaranteed. +- Dates are expected to be received in one of the ISO 8601 formats, as per the [JSON API spec recommendation](http://jsonapi.org/recommendations/#date-and-time-fields); +- Dates are always sent in full ISO 8601 format, with local timezone and without milliseconds (example: `2001-02-03T14:05:06+07:00`). ## TODO diff --git a/src/decorators/attribute.decorator.ts b/src/decorators/attribute.decorator.ts index 216663bd..3a9801aa 100644 --- a/src/decorators/attribute.decorator.ts +++ b/src/decorators/attribute.decorator.ts @@ -11,7 +11,7 @@ export function Attribute(config: any = {}) { } } else { if (dataType === Date) { - return dateFormat(value, 'YYYY-MM-DDTHH:mm:ss[Z]'); + return dateFormat(value, 'YYYY-MM-DDTHH:mm:ssZ'); } }