UNPKG

1.8 kBTypeScriptView Raw
1import { NgbDateStruct } from './ngb-date-struct';
2export declare function NGB_DATEPICKER_PARSER_FORMATTER_FACTORY(): NgbDateISOParserFormatter;
3/**
4 * An abstract service for parsing and formatting dates for the
5 * [`NgbInputDatepicker`](#/components/datepicker/api#NgbInputDatepicker) directive.
6 * Converts between the internal `NgbDateStruct` model presentation and a `string` that is displayed in the
7 * input element.
8 *
9 * When user types something in the input this service attempts to parse it into a `NgbDateStruct` object.
10 * And vice versa, when users selects a date in the calendar with the mouse, it must be displayed as a `string`
11 * in the input.
12 *
13 * Default implementation uses the ISO 8601 format, but you can provide another implementation via DI
14 * to use an alternative string format or a custom parsing logic.
15 *
16 * See the [date format overview](#/components/datepicker/overview#date-model) for more details.
17 */
18export declare abstract class NgbDateParserFormatter {
19 /**
20 * Parses the given `string` to an `NgbDateStruct`.
21 *
22 * Implementations should try their best to provide a result, even
23 * partial. They must return `null` if the value can't be parsed.
24 */
25 abstract parse(value: string): NgbDateStruct | null;
26 /**
27 * Formats the given `NgbDateStruct` to a `string`.
28 *
29 * Implementations should return an empty string if the given date is `null`,
30 * and try their best to provide a partial result if the given date is incomplete or invalid.
31 */
32 abstract format(date: NgbDateStruct | null): string;
33}
34export declare class NgbDateISOParserFormatter extends NgbDateParserFormatter {
35 parse(value: string): NgbDateStruct | null;
36 format(date: NgbDateStruct | null): string;
37}