Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { DateTime } from 'luxon';
import fecha from 'fecha';
import { format as dateFnsFormat } from 'date-fns';
import dateFnsLocaleJa from 'date-fns/locale/ja';
import dateformat from 'dateformat';
import litdate from 'lit-date';
const date = new Date('2000-01-06T12:34:56.789Z');
const expected = '1月6日(木)';
// Prepare
const dayOfWeekToName = ({ dayOfWeek }) => ['日', '月', '火', '水', '木', '金', '土'][dayOfWeek];
Object.assign(dateformat.i18n, {
dayNames: ['日', '月', '火', '水', '木', '金', '土'],
});
Object.assign(fecha.i18n, {
dayNamesShort: ['日', '月', '火', '水', '木', '金', '土'],
});
suite('Advanced usage', () => {
benchmark('moment', () => {
const actual = moment(date)
.locale('ja')
.format('M月D日(ddd)');
console.assert(actual === expected);
});
benchmark('luxon', () => {
const actual = DateTime.fromJSDate(date)
.setLocale('ja')
.toFormat('M月d日(ccc)');
console.assert(actual === expected);
});
beforeMount() {
fecha.i18n = {
dayNames: this.i18n['day-names'],
dayNamesShort: this.shortenString(this.i18n['day-names'], 3),
monthNames: this.i18n['month-names'],
monthNamesShort: this.shortenString(this.i18n['month-names'], 3),
amPm: ['am', 'pm'],
// D is the day of the month, function returns something like... 3rd or 11th
DoFn: function (D) {
return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
}
};
if(this.checkIn &&
(this.getMonthDiff(this.getNextMonth(new Date(this.startDate)), this.checkIn) > 0 ||
this.getMonthDiff(this.startDate, this.checkIn) > 0)){
this.createMonth(new Date(this.startDate));
const count = this.getMonthDiff(this.startDate, this.checkIn)
let nextMonth = new Date(this.startDate)
private getFechaMonthNames(style: TranslationWidth): string[] {
switch (style) {
case TranslationWidth.SHORT:
return fecha.i18n.monthNamesShort;
case TranslationWidth.LONG:
return fecha.i18n.monthNames;
}
}
private getFechaMonthNames(style: TranslationWidth): string[] {
switch (style) {
case TranslationWidth.SHORT:
return fecha.i18n.monthNamesShort;
case TranslationWidth.LONG:
return fecha.i18n.monthNames;
}
}
private setFechaLocaleData(config: I18nConfig) {
fecha.i18n.dayNames = config.dayNames[TranslationWidth.LONG];
fecha.i18n.dayNamesShort = config.dayNames[TranslationWidth.SHORT];
fecha.i18n.monthNames = config.monthNames[TranslationWidth.LONG];
fecha.i18n.monthNamesShort = config.monthNames[TranslationWidth.SHORT];
}
}
private setFechaLocaleData(config: I18nConfig) {
fecha.i18n.dayNames = config.dayNames[TranslationWidth.LONG];
fecha.i18n.dayNamesShort = config.dayNames[TranslationWidth.SHORT];
fecha.i18n.monthNames = config.monthNames[TranslationWidth.LONG];
fecha.i18n.monthNamesShort = config.monthNames[TranslationWidth.SHORT];
}
}
private setFechaLocaleData(config: I18nConfig) {
fecha.i18n.dayNames = config.dayNames[TranslationWidth.LONG];
fecha.i18n.dayNamesShort = config.dayNames[TranslationWidth.SHORT];
fecha.i18n.monthNames = config.monthNames[TranslationWidth.LONG];
fecha.i18n.monthNamesShort = config.monthNames[TranslationWidth.SHORT];
}
}
private setFechaLocaleData(config: I18nConfig) {
fecha.i18n.dayNames = config.dayNames[TranslationWidth.LONG];
fecha.i18n.dayNamesShort = config.dayNames[TranslationWidth.SHORT];
fecha.i18n.monthNames = config.monthNames[TranslationWidth.LONG];
fecha.i18n.monthNamesShort = config.monthNames[TranslationWidth.SHORT];
}
}