UNPKG

@progress/kendo-angular-intl

Version:

Kendo UI Internationalization for Angular components

66 lines (65 loc) 2.65 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Pipe } from '@angular/core'; import { IntlService } from './intl.service'; import * as i0 from "@angular/core"; import * as i1 from "./intl.service"; const isNumeric = (value) => !isNaN(value - parseFloat(value)); /** * Formats a date value to a string based on the requested format. * This pipe uses the [IntlService]({% slug api_intl_intlservice %}). * * @example * ```html * <ul> * <li>{{date | kendoDate }}</li> * <li>{{milliseconds | kendoDate: 'M/dd/yyy' }}</li> * <li>{{stringDate | kendoDate: 'G' }}</li> * </ul> * ``` */ export class DatePipe { intlService; /** * @hidden */ constructor(intlService) { this.intlService = intlService; } /** * Converts a `Date` object into a string based on the specified format. * If no format is provided, the default short date format is used. * * @param value - The date to format. * @param format - The format string or options (optional). * @param localeId - The ID of the locale which will be used instead of the default one (optional). * @returns The formatted date as a string. */ transform(value, format = "", localeId) { value = this.normalize(value); if (value) { return this.intlService.formatDate(value, format, localeId); } return value; } normalize(value) { if (value && typeof value === 'string') { value = this.intlService.parseDate(value); } else if (value && isNumeric(value)) { value = new Date(parseFloat(value)); } return value; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DatePipe, deps: [{ token: i1.IntlService }], target: i0.ɵɵFactoryTarget.Pipe }); static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: DatePipe, isStandalone: true, name: "kendoDate" }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DatePipe, decorators: [{ type: Pipe, args: [{ name: 'kendoDate', standalone: true }] }], ctorParameters: () => [{ type: i1.IntlService }] });