Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
fix(base-resource.model): Change detect used timezone fore date fields
Browse files Browse the repository at this point in the history
  • Loading branch information
EndyKaufman committed Jul 24, 2017
1 parent 12c5a2d commit 2264941
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/base/base-models/base-resource.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { translate } from './../../shared/utils';

export class BaseResourceModel {
className = 'ResourceModel';

pkFieldName: string;
pkIsNumber: boolean;
dateAsStringFormat = 'DD.MM.YYYY';
Expand Down Expand Up @@ -78,8 +79,7 @@ export class BaseResourceModel {
}
format() {
const current: any = this.constructor;
const result = this.formatByFields(current.meta());
return result;
return this.formatByFields(current.meta());
}
formatByFields(meta: any): any {
const obj: any = {};
Expand All @@ -96,10 +96,15 @@ export class BaseResourceModel {
}
}
if (dateFields.length > 0) {
const tzoffset = (new Date()).getTimezoneOffset() * 60000;
for (const key in this) {
if (dateFields.indexOf(key) !== -1) {
if (obj[key]) {
let tzoffset = 0;
try {
tzoffset = (moment(this[key]).toDate()).getTimezoneOffset() * 60000;
} catch (err) {
tzoffset = (new Date()).getTimezoneOffset() * 60000;
}
try {
obj[key] = moment(+moment(this[key]).toDate() - tzoffset).toISOString().slice(0, -1);
} catch (err) {
Expand Down

0 comments on commit 2264941

Please # to comment.