import { Injectable } from '@angular/core';
import * as moment from "moment";

@Injectable({
  providedIn: 'root'
})
export class AppService {

  constructor() { }

  formatDateTime(datetime: number, date:boolean, time: boolean) {
    let format ;
    if ( date && time ){
      format = 'YYYY.MM.DD HH:mm';
    } else if (date){
      format = 'YYYY.MM.DD';
    } else  {
      format = 'HH:mm';
    }
    return this.dateToMoment(datetime).utc().format(format);
  }

  dateToMoment(date: number) {
    return moment.unix(date);
  }
}
