/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Component, OnInit, OnDestroy, Input, Output, EventEmitter, ChangeDetectorRef } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { InaxTranslateService } from '../../../../@inax/translate'; import { Subscription } from 'rxjs/Rx'; import { CommonUiResourceManager } from './../resources/resource.service'; @Component({ selector: 'inax-date-time', templateUrl: './@inax/commonUi/src/datetime/datetime.component.html', styleUrls: ['./@inax/commonUi/src/datetime/datetime.component.css'] }) export class DateTimeComponent implements OnInit, OnDestroy { private _date: Date; @Input() format: string = 'EEE MMM/dd
HH:mm:ss'; @Input() format2: string = ''; @Output() TimeChanged = new EventEmitter(); public get DateTime(): Date { return this._date; } public set DateTime(date: Date){ } constructor( private _resourceManager: CommonUiResourceManager, private _changeDetectorRef: ChangeDetectorRef ){ } ngOnInit(){ this.updateService(); } ngOnDestroy(){ } public updateService(){ //to avoid recursion in updateTime (enables instant call of updateTime on format swap) this.updateTime(); setTimeout(()=> this.updateService(), 200); } public updateTime(){ this._date = new Date(); this.TimeChanged.emit(this._date); this._changeDetectorRef.detectChanges(); } public switchFormat(): void{ if (this.format === ''){ return; } let tempFormat = this.format; this.format = this.format2; this.format2 = tempFormat; this.updateTime(); } //deprecated because of pipes /* public formatDate(date: Date): string{ let dd=this.doubleDigit; let wd=this.getWeekday; switch(this._activeFormat){ case 'default': let y=date.getFullYear(); let M=date.getMonth(); let d=date.getDate(); let D=date.getDay(); let h = date.getHours(); let m = date.getMinutes(); let s = date.getSeconds(); let formattedDate = wd(D)+' '+dd(d)+'/'+dd(M)+'/'+y+' '+dd(h)+":"+dd(m)+":"+dd(s); return formattedDate; default: { if(this.format != 'HH:mm:ss'){ return 'success'; } let h = date.getHours(); let m = date.getMinutes(); let s = date.getSeconds(); return dd(h)+":"+dd(m)+":"+dd(s); } } } private doubleDigit(x: number): string{ if (x < 10){ return "0"+x; } else { return x.toString(); } } private getWeekday(d: number): string{ switch(d){ case 0: return 'Sun'; case 1: return 'Mon'; case 2: return 'Tue'; case 3: return 'Wed'; case 4: return 'Thu'; case 5: return 'Fri'; case 6: return 'Sat'; default: return ''; } } */ }