all files / common/core/pipes/ moment.pipe.ts

88.89% Statements 8/9
100% Branches 2/2
33.33% Functions 1/3
85.71% Lines 6/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                                               
/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
 
import { Pipe, PipeTransform} from '@angular/core';
import * as moment_ from 'moment';
const moment: (value?: any, format?: string) => moment_.Moment = (<any>moment_).default || moment_;
 
/**
 * Use moment to transform string to date
 * @deprecated
 */
@Pipe({ name: 'stringToDateFormat' })
export class StringToDateFormatPipe implements PipeTransform {
    /**
     * Create a date from a string given in parameter using moment
     *
     * @param dateString date in string format 'DD.MM.YYYY HH:mm:ss'
     * @param format format choosen for the date
     */
    public transform(dateString: any, format: string): any {
        return moment(dateString, 'DD.MM.YYYY HH:mm:ss').format(format);
    }
}