1 import { Component, Input, OnInit, OnChanges } from '@angular/core'
2 import { DatePipe } from '@angular/common'
3 import { FromNowPipe } from '../angular/from-now.pipe'
6 selector: 'my-date-toggle',
7 templateUrl: './date-toggle.component.html',
8 styleUrls: [ './date-toggle.component.scss' ],
9 providers: [ DatePipe, FromNowPipe ]
11 export class DateToggleComponent implements OnInit, OnChanges {
13 @Input() toggled = false
19 private datePipe: DatePipe,
20 private fromNowPipe: FromNowPipe
32 this.toggled = !this.toggled
36 return this.toggled ? this.dateRelative : this.dateAbsolute
40 return this.toggled ? this.dateAbsolute : this.dateRelative
43 private updateDates () {
44 this.dateRelative = this.fromNowPipe.transform(this.date)
45 this.dateAbsolute = this.datePipe.transform(this.date, 'long')