
export class StringHelper {

  static getPersonShortTitle(person: any): string {
    return `${person.lastName} ${person.firstName ? person.firstName.substr(0, 1) + '.' : ''}${person.middleName ? person.middleName.substr(0, 1) + '.' : ''}`;
  }

  static getISODate(date: Date): string {
    if (!date) {
      return undefined;
    }

    return date.getFullYear().toString().padStart(4, '0') +
      '-' + (date.getMonth() + 1).toString().padStart(2, '0') +
      '-' + date.getDate().toString().padStart(2, '0');
  }

  static getRuTimeWithSeconds(date: Date): string {
    if (!date) {
      return undefined;
    }

    if (!(date instanceof Date)) {
      date = new Date(date);
    }

    return date.getDate().toString().padStart(2, '0') +
      '.' + (date.getMonth() + 1).toString().padStart(2, '0') +
      '.' + date.getFullYear().toString().padStart(4, '0') +
      ' ' + date.getHours().toString().padStart(2, '0') +
      ':' + date.getMinutes().toString().padStart(2, '0') +
      ':' + date.getSeconds().toString().padStart(2, '0');
  }
}
