@telerik/kendo-intl
Advanced tools
Comparing version 0.12.3 to 0.13.0
@@ -23,3 +23,3 @@ /** | ||
*/ | ||
standAlone?: string; | ||
standAlone?: boolean; | ||
} | ||
@@ -26,0 +26,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { DateFormatNameOptions } from './cldr'; | ||
/** | ||
@@ -11,2 +13,7 @@ * Settings for the formatDate and parseDate functions. | ||
/** | ||
* Defines the exact pattern to be used to format the date. | ||
*/ | ||
pattern?: string; | ||
/** | ||
* Specifies which of the locale `dateFormats` should be used to format the value. | ||
@@ -97,10 +104,26 @@ */ | ||
export interface DateFormatPart { | ||
/** | ||
* Specifies the type of the format part. | ||
*/ | ||
type?: 'era' | 'year' | 'quarter' | 'month' | 'day' | 'weekday' | 'hour' | 'minute' | 'second' | 'dayperiod' | 'zone' | 'literal'; | ||
/** | ||
* Specifies the pattern of the format part. | ||
*/ | ||
pattern?: string; | ||
/** | ||
* Specifies the format names options. | ||
*/ | ||
names?: DateFormatNameOptions; | ||
} | ||
/** | ||
* Returns the full format based on the Date object and the specified format. If no format is provided, the default short date format is used. | ||
* Splits the date format into objects containing information about each part of the pattern. | ||
* | ||
* @param value The date to format. | ||
* @param format The format string or options. | ||
* @param locale The optional locale id. If not specified, the `"en"` locale id is used. | ||
* @returns The full date format. | ||
* @returns The date format parts. | ||
*/ | ||
export function dateFormatString(value: Date, format: string|DateFormatOptions, locale?: string): string; | ||
export function splitDateFormat(format: string|DateFormatOptions, locale?: string): DateFormatPart[]; |
export { default as formatDate } from './dates/format-date'; | ||
export { default as parseDate } from './dates/parse-date'; | ||
export { default as dateFormatString } from './dates/date-format-string'; | ||
export { default as splitDateFormat } from './dates/split-date-format'; | ||
//# sourceMappingURL=dates.js.map |
@@ -200,2 +200,6 @@ import formatString from '../common/format-string'; | ||
} else if (format) { | ||
if (format.pattern) { | ||
return format.pattern; | ||
} | ||
var skeleton = format.skeleton; | ||
@@ -202,0 +206,0 @@ if (!skeleton) { |
@@ -1,8 +0,204 @@ | ||
import dateGenericFormat from './date-generic-format'; | ||
import { localeInfo, firstDay } from '../cldr'; | ||
import formatString from '../common/format-string'; | ||
import datePattern from './date-pattern'; | ||
import formatNames from './format-names'; | ||
import pad from '../common/pad'; | ||
import isDate from '../common/is-date'; | ||
import { dateFormatRegExp } from './constants'; | ||
function formatDayOfWeekIndex(day, formatLength, localeInfo) { | ||
var firstDayIndex = firstDay(localeInfo); | ||
var dayIndex; | ||
if (day < firstDayIndex) { | ||
dayIndex = 7 - firstDayIndex + day; | ||
} else { | ||
dayIndex = day - firstDayIndex; | ||
} | ||
return dayIndex + 1; | ||
} | ||
function formatMonth(month, formatLength, info, standAlone) { | ||
if (formatLength <= 2) { | ||
return pad(month + 1, formatLength); | ||
} | ||
return formatNames(info, "months", formatLength, standAlone)[month]; | ||
} | ||
function formatQuarter(date, formatLength, info, standAlone) { | ||
var quarter = Math.floor(date.getMonth() / 3); | ||
if (formatLength < 3) { | ||
return quarter + 1; | ||
} | ||
return formatNames(info, "quarters", formatLength, standAlone)[quarter]; | ||
} | ||
function formatTimeZone(date, info, options) { | ||
var shortHours = options.shortHours; | ||
var optionalMinutes = options.optionalMinutes; | ||
var separator = options.separator; | ||
var localizedName = options.localizedName; | ||
var zZeroOffset = options.zZeroOffset; | ||
var offset = date.getTimezoneOffset() / 60; | ||
if (offset === 0 && zZeroOffset) { | ||
return "Z"; | ||
} | ||
var sign = offset <= 0 ? "+" : "-"; | ||
var hoursMinutes = Math.abs(offset).toString().split("."); | ||
var minutes = hoursMinutes[1] || 0; | ||
var result = sign + (shortHours ? hoursMinutes[0] : pad(hoursMinutes[0], 2)); | ||
if (minutes || !optionalMinutes) { | ||
result += (separator ? ":" : "") + pad(minutes, 2); | ||
} | ||
if (localizedName) { | ||
var localizedFormat = offset === 0 ? info.calendar.gmtZeroFormat : info.calendar.gmtFormat; | ||
result = formatString(localizedFormat, result); | ||
} | ||
return result; | ||
} | ||
function formatDayOfWeek(date, formatLength, info, standAlone) { | ||
var result; | ||
if (formatLength < 3) { | ||
result = formatDayOfWeekIndex(date.getDay(), formatLength, info); | ||
} else { | ||
result = formatNames(info, "days", formatLength, standAlone)[date.getDay()]; | ||
} | ||
return result; | ||
} | ||
var formatters = {}; | ||
formatters.d = function(date, formatLength) { | ||
return pad(date.getDate(), formatLength); | ||
}; | ||
formatters.E = function(date, formatLength, info) { | ||
return formatNames(info, "days", formatLength)[date.getDay()]; | ||
}; | ||
formatters.M = function(date, formatLength, info) { | ||
return formatMonth(date.getMonth(), formatLength, info, false); | ||
}; | ||
formatters.L = function(date, formatLength, info) { | ||
return formatMonth(date.getMonth(), formatLength, info, true); | ||
}; | ||
formatters.y = function(date, formatLength) { | ||
var year = date.getFullYear(); | ||
if (formatLength === 2) { | ||
year = year % 100; | ||
} | ||
return pad(year, formatLength); | ||
}; | ||
formatters.h = function(date, formatLength) { | ||
var hours = date.getHours() % 12 || 12; | ||
return pad(hours, formatLength); | ||
}; | ||
formatters.H = function(date, formatLength) { | ||
return pad(date.getHours(), formatLength); | ||
}; | ||
formatters.m = function(date, formatLength) { | ||
return pad(date.getMinutes(), formatLength); | ||
}; | ||
formatters.s = function(date, formatLength) { | ||
return pad(date.getSeconds(), formatLength); | ||
}; | ||
formatters.S = function(date, formatLength) { | ||
var milliseconds = date.getMilliseconds(); | ||
var result; | ||
if (milliseconds !== 0) { | ||
result = String(date.getMilliseconds() / 1000).split(".")[1].substr(0, formatLength); | ||
} else { | ||
result = pad("", formatLength); | ||
} | ||
return result; | ||
}; | ||
formatters.a = function(date, formatLength, info) { | ||
return formatNames(info, "dayPeriods", formatLength)[date.getHours() < 12 ? "am" : "pm"]; | ||
}; | ||
formatters.z = function(date, formatLength, info) { | ||
return formatTimeZone(date, info, { | ||
shortHours: formatLength < 4, | ||
optionalMinutes: formatLength < 4, | ||
separator: true, | ||
localizedName: true | ||
}); | ||
}; | ||
formatters.Z = function(date, formatLength, info) { | ||
return formatTimeZone(date, info, { | ||
separator: formatLength > 3, | ||
localizedName: formatLength === 4, | ||
zZeroOffset: formatLength === 5 | ||
}); | ||
}; | ||
formatters.x = function(date, formatLength, info) { | ||
return formatTimeZone(date, info, { | ||
optionalMinutes: formatLength === 1, | ||
separator: formatLength === 3 || formatLength === 5 | ||
}); | ||
}; | ||
formatters.X = function(date, formatLength, info) { | ||
return formatTimeZone(date, info, { | ||
optionalMinutes: formatLength === 1, | ||
separator: formatLength === 3 || formatLength === 5, | ||
zZeroOffset: true | ||
}); | ||
}; | ||
formatters.G = function(date, formatLength, info) { | ||
var era = date.getFullYear() >= 0 ? 1 : 0; | ||
return formatNames(info, "eras", formatLength)[era]; | ||
}; | ||
formatters.e = formatDayOfWeek; | ||
formatters.c = function(date, formatLength, info) { | ||
return formatDayOfWeek(date, formatLength, info, true); | ||
}; | ||
formatters.q = function(date, formatLength, info) { | ||
return formatQuarter(date, formatLength, info, true); | ||
}; | ||
formatters.Q = formatQuarter; | ||
export default function formatDate(date, format, locale) { | ||
if ( locale === void 0 ) locale = "en"; | ||
return dateGenericFormat(date, format, locale, false); | ||
if (!isDate(date)) { | ||
return date; | ||
} | ||
var info = localeInfo(locale); | ||
var pattern = datePattern(format, info); | ||
return pattern.replace(dateFormatRegExp, function(match) { | ||
var formatLength = match.length; | ||
var result; | ||
if (match.includes("'") || match.includes("\"")) { | ||
result = match.slice(1, formatLength - 1); | ||
} else { | ||
result = formatters[match[0]](date, formatLength, info); | ||
} | ||
return result; | ||
}); | ||
} | ||
//# sourceMappingURL=format-date.js.map |
import dateFormatNames from '../cldr/date-format-names'; | ||
import dateNameType from './date-name-type'; | ||
function dateNameType(formatLength) { | ||
var nameType; | ||
if (formatLength <= 3) { | ||
nameType = "abbreviated"; | ||
} else if (formatLength === 4) { | ||
nameType = "wide"; | ||
} else if (formatLength === 5) { | ||
nameType = "narrow"; | ||
} else if (formatLength === 6) { | ||
nameType = "short"; | ||
} | ||
return nameType; | ||
} | ||
export default function formatNames(locale, type, formatLength, standAlone, lower) { | ||
@@ -19,0 +5,0 @@ return dateFormatNames(locale, { |
{ | ||
"name": "@telerik/kendo-intl", | ||
"description": "A package exporting functions for date and number parsing and formatting", | ||
"version": "0.12.3", | ||
"version": "0.13.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
569217
84
5614