Skip to content

Commit a7c5e08

Browse files
docs: document splitDateFormat method
1 parent 6487990 commit a7c5e08

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docs/date-formatting/api.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,24 @@ Defines the locale id.
159159
#### Returns `String`
160160

161161
The formatted date.
162+
163+
#### splitDateFormat
164+
165+
Returns information about the individual segments of a format.
166+
The returned objects contain the segment type(year, month, etc.), the pattern and information about the type of names that are used for the pattern.
167+
168+
## Parameters
169+
170+
#### format `String|Object`
171+
172+
Specifies a string representing a predefined or custom date format, or a configuration object.
173+
174+
#### locale `String`
175+
176+
Defines the locale id.
177+
178+
## Return Value
179+
180+
#### Returns `Array`
181+
182+
An array with the information about the format segments.

docs/date-formatting/index.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ The following specifiers can be used in the custom formats.
121121

122122
formatDate(new Date(2011, 0, 1), "yy"); // 11
123123

124-
formatDate(new Date(111, 0, 1), "yyyy"); // 0111
124+
formatDate(new Date(111, 0, 1), "yyyy"); // 0111
125125

126126
* **The `"Q"` specifier**—Renders a quarter of the year.
127127

@@ -321,6 +321,25 @@ The supported types of options are:
321321

322322
formatDate(new Date(2000, 10, 6), { year: "numeric", month: "long" }); // November 2000
323323

324+
# Splitting date formats
325+
326+
In some cases you may need more detailed information about the format itself in order to utilize or manipulate individual parts of the format.
327+
The `splitDateFormat` method can be used to get information about each individual segment of the format.
328+
329+
For example, using abbreviated names in a predefined format can be implemented in the following way.
330+
331+
import { formatDate, splitDateFormat } from '@telerik/kendo-intl';
332+
333+
const date = new Date(2000, 0, 1);
334+
335+
splitDateFormat({ date: 'full' }).map(part => {
336+
if (part.type !== 'literal') {
337+
return formatDate(date, { pattern: part.pattern.slice(0, 3) });
338+
}
339+
340+
return part.pattern;
341+
}).join(''); //Sat, Jan 1, 2000
342+
324343
## Suggested Links
325344

326345
* [Date Formatting API]({% slug dateformatapi_internalization %})

0 commit comments

Comments
 (0)