From 1bd59cbbf8d810701b2d9175398fe29f66293324 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 29 Jul 2017 17:07:43 +0200 Subject: [PATCH] Fix date format in category service. --- src/operations/category.service.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/operations/category.service.ts b/src/operations/category.service.ts index 44f33c5..411d4b7 100644 --- a/src/operations/category.service.ts +++ b/src/operations/category.service.ts @@ -1,5 +1,7 @@ // vim: set tw=80 ts=2 sw=2 sts=2: +import * as moment from 'moment'; + import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; @@ -13,14 +15,23 @@ export class CategoryService { private restangular: Restangular ) {} + formatDate(date: Date|string) { + if(date instanceof Date) { + return moment(date).format('YYYY-MM-DD'); + } + + return date; + } + query(id: number, minDate: Date = null, maxDate: Date = null): Observable { - var dateRange: any; + var dateRange: any = {}; + if(minDate) { - dateRange.begin = minDate; + dateRange.begin = this.formatDate(minDate); } if(maxDate) { - dateRange.end = maxDate; + dateRange.end = this.formatDate(maxDate); } return this.restangular.one('account', id).getList('category', dateRange);