import * as dateFormatter from 'date-and-time';

export class DateTimeFunctions {
  /**
   * Obtain the current date of the system in format mm-dd-year .
   *
   * @return {String} return the date in string format
   * @private
   */
  public getDateInDayMonthYear = ( date: Date ): string => dateFormatter.format( date, 'MM-DD-YYYY' );

  /**
   * Obtain the current time of the system in format hh:mm:ss .
   *
   * @return {String} return the time in string format
   * @private
   */
  public getTimeInHHMMSS = ( date: Date, separator: string ): string => dateFormatter.format( date, 'HH' + separator + 'mm' + separator + 'ss' );

  /**
   * transform the time from seconds to HH:MM:ss
   *
   * @param time time that is going to be converted
   * @private
   */
  public convertTimeFromNanoSecondsToHHMMSS = ( time: number ): string => {
    const date = new Date( );
    time = typeof time === 'undefined' || time === 0 ? time = 0 : time;
    date.setSeconds( time === 0 ? 0 : Math.floor( time / 1000000000 ) ); // specify value for SECONDS here
    const result = date.toISOString().substr( 11, 8 );
    return result;
  };
}
