diff options
Diffstat (limited to 'date-fns/scripts/build/localeSnapshots/renderFormatParse')
-rw-r--r-- | date-fns/scripts/build/localeSnapshots/renderFormatParse/formatParseTokens.js | 218 | ||||
-rw-r--r-- | date-fns/scripts/build/localeSnapshots/renderFormatParse/index.js | 59 |
2 files changed, 277 insertions, 0 deletions
diff --git a/date-fns/scripts/build/localeSnapshots/renderFormatParse/formatParseTokens.js b/date-fns/scripts/build/localeSnapshots/renderFormatParse/formatParseTokens.js new file mode 100644 index 0000000..5631d95 --- /dev/null +++ b/date-fns/scripts/build/localeSnapshots/renderFormatParse/formatParseTokens.js @@ -0,0 +1,218 @@ +const yearDates = [ + new Date(1987, 1, 11, 12, 13, 14, 15), + new Date(0, 0, 1, 12, 13, 14, 15).setFullYear(5, 0, 1) +] + +const quarterDates = [ + new Date(2019, 0, 1, 12, 13, 14, 15), + new Date(2019, 3, 1, 12, 13, 14, 15) +] + +const monthDates = [ + new Date(2019, 1, 11, 12, 13, 14, 15), + new Date(2019, 6, 10, 12, 13, 14, 15) +] + +const weekOfYearDates = [ + new Date(2019, 0, 1, 12, 13, 14, 15), + new Date(2019, 11, 1, 12, 13, 14, 15) +] + +const dayOfMonthDates = [ + new Date(2019, 1, 11, 12, 13, 14, 15), + new Date(2019, 1, 28, 12, 13, 14, 15) +] + +const dayOfYearDates = [ + new Date(2019, 1, 11, 12, 13, 14, 15), + new Date(2019, 11, 31, 12, 13, 14, 15) +] + +const dayOfWeekDates = [ + new Date(2019, 1, 11, 12, 13, 14, 15), + new Date(2019, 1, 15, 12, 13, 14, 15) +] + +const timeOfDayDates = [ + new Date(2019, 1, 11, 11, 13, 14, 15), + new Date(2019, 1, 11, 14, 13, 14, 15), + new Date(2019, 1, 11, 19, 13, 14, 15), + new Date(2019, 1, 11, 2, 13, 14, 15) +] + +const hourDates = [ + new Date(2019, 1, 11, 11, 13, 14, 15), + new Date(2019, 1, 11, 23, 13, 14, 15) +] + +const localizedDates = [ + new Date(1987, 1, 11, 12, 13, 14, 15), + new Date(1453, 4, 29, 23, 59, 59, 999) +] + +const formatParseTokens = [ + { + title: 'Calendar year', + tokens: ['yo'], + dates: yearDates + }, + + { + title: 'Local week-numbering year', + tokens: ['Yo'], + dates: yearDates, + options: { useAdditionalWeekYearTokens: true } + }, + + { + title: 'Quarter (formatting)', + tokens: ['Qo', 'QQQ', 'QQQQ', 'QQQQQ'], + dates: quarterDates + }, + + { + title: 'Quarter (stand-alone)', + tokens: ['qo', 'qqq', 'qqqq'], + dates: quarterDates + }, + + { + title: 'Month (formatting)', + tokens: ['Mo', 'MMM', 'MMMM', 'MMMMM'], + dates: monthDates + }, + + { + title: 'Month (stand-alone) ', + tokens: ['Lo', 'LLL', 'LLLL', 'LLLLL'], + dates: monthDates + }, + + { + title: 'Local week of year', + tokens: ['wo'], + dates: weekOfYearDates + }, + + { + title: 'ISO week of year', + tokens: ['Io'], + dates: weekOfYearDates + }, + + { + title: 'Day of month', + tokens: ['do'], + dates: dayOfMonthDates + }, + + { + title: 'Day of year', + tokens: ['Do'], + dates: dayOfYearDates, + options: { useAdditionalDayOfYearTokens: true } + }, + + { + title: 'Day of week (formatting)', + tokens: ['E', 'EE', 'EEE', 'EEEE', 'EEEEE', 'EEEEEE'], + dates: dayOfWeekDates + }, + + { + title: 'ISO day of week (formatting)', + tokens: ['io', 'iii', 'iiii', 'iiiii', 'iiiiii'], + dates: dayOfWeekDates + }, + + { + title: 'Local day of week (formatting)', + tokens: ['eo', 'eee', 'eeee', 'eeeee', 'eeeeee'], + dates: dayOfWeekDates + }, + + { + title: 'Local day of week (stand-alone)', + tokens: ['co', 'ccc', 'cccc', 'ccccc', 'cccccc'], + dates: dayOfWeekDates + }, + + { + title: 'AM, PM', + tokens: ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'], + dates: timeOfDayDates + }, + + { + title: 'AM, PM, noon, midnight', + tokens: ['b', 'bb', 'bbb', 'bbbb', 'bbbbb'], + dates: timeOfDayDates + }, + + { + title: 'Flexible day period', + tokens: ['B', 'BB', 'BBB', 'BBBB', 'BBBBB'], + dates: timeOfDayDates + }, + + { + title: 'Hour [1-12]', + tokens: ['ho'], + dates: hourDates + }, + + { + title: 'Hour [0-23]', + tokens: ['Ho'], + dates: hourDates + }, + + { + title: 'Hour [0-11]', + tokens: ['Ko'], + dates: hourDates + }, + + { + title: 'Hour [1-24]', + tokens: ['ko'], + dates: hourDates + }, + + { + title: 'Minute', + tokens: ['mo'], + dates: [ + new Date(2019, 0, 1, 12, 1, 14, 15), + new Date(2019, 3, 1, 12, 55, 14, 15) + ] + }, + + { + title: 'Second', + tokens: ['so'], + dates: [ + new Date(2019, 0, 1, 12, 13, 1, 15), + new Date(2019, 3, 1, 12, 13, 55, 15) + ] + }, + + { + title: 'Long localized date', + tokens: ['P', 'PP', 'PPP', 'PPPP'], + dates: localizedDates + }, + + { + title: 'Long localized time', + tokens: ['p', 'pp', 'ppp', 'pppp'], + dates: localizedDates + }, + + { + title: 'Combination of date and time', + tokens: ['Pp', 'PPpp', 'PPPppp', 'PPPPpppp'], + dates: localizedDates + } +] +export default formatParseTokens diff --git a/date-fns/scripts/build/localeSnapshots/renderFormatParse/index.js b/date-fns/scripts/build/localeSnapshots/renderFormatParse/index.js new file mode 100644 index 0000000..2ddcb10 --- /dev/null +++ b/date-fns/scripts/build/localeSnapshots/renderFormatParse/index.js @@ -0,0 +1,59 @@ +import format from '../../../../src/format' +import isValid from '../../../../src/isValid' +import parse from '../../../../src/parse' +import toDate from '../../../../src/toDate' +import formatParseTokens from './formatParseTokens' + +export default function renderFormatParse(locale) { + return `## \`format\` and \`parse\` + +| Title | Token string | Date | \`format\` result | \`parse\` result | +|-|-|-|-|-| +${formatParseTokens + .map(({ title, tokens, dates, options = {}, skipParse }) => { + return tokens + .map((token, tokenIndex) => { + return dates + .map((date, dateIndex) => { + const dateString = toDate(date).toISOString() + const formatResult = format( + date, + token, + Object.assign({ locale }, options) + ) + let parsedDate + try { + parsedDate = + !skipParse && + parse( + formatResult, + token, + date, + Object.assign({ locale }, options) + ) + } catch (_err) { + parsedDate = 'Errored' + } + + const parseResult = skipParse + ? 'NA' + : parsedDate === 'Errored' + ? parsedDate + : isValid(parsedDate) + ? parsedDate.toISOString() + : 'Invalid Date' + + if (dateIndex === 0 && tokenIndex === 0) { + return `| ${title} | ${token} | ${dateString} | ${formatResult} | ${parseResult} |` + } else if (dateIndex === 0) { + return `| | ${token} | ${dateString} | ${formatResult} | ${parseResult} |` + } else { + return `| | | ${dateString} | ${formatResult} | ${parseResult} |` + } + }) + .join('\n') + }) + .join('\n') + }) + .join('\n')}` +} |