@khatastroffik/react-text-renderer-components
Version:
a zero-dependencies component library providing (pure) text rendering for common and custom data/field types.
65 lines (57 loc) • 2.99 kB
JavaScript
var $b8f6b02ccb3471cd$exports = require("./CacheManager.5cf53329.js");
var $d05063a33f9bc032$exports = require("./AbstractRenderer.51d1084a.js");
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "defaultWeekRendererFormatOptions", () => $daef0ad3f06d8703$export$2f19cc1069a8e827);
$parcel$export(module.exports, "WeekRenderer", () => $daef0ad3f06d8703$export$aac6dcdc68811241);
$parcel$export(module.exports, "calcISOWeek", () => $daef0ad3f06d8703$export$d753131d7d9b4cdb);
const $daef0ad3f06d8703$export$2f19cc1069a8e827 = {
minimumIntegerDigits: 2,
useGrouping: false
};
const $daef0ad3f06d8703$var$_WeekFormatterCache = {};
class $daef0ad3f06d8703$export$aac6dcdc68811241 extends (0, $d05063a33f9bc032$exports.AbstractRenderer) {
getFormatedText() {
if (this.value) {
const options = {
...$daef0ad3f06d8703$export$2f19cc1069a8e827,
...this.props.minimumIntegerDigits && {
minimumIntegerDigits: this.props.minimumIntegerDigits
},
...this.props.numberingSystem && {
numberingSystem: this.props.numberingSystem
}
};
const isoWeek = $daef0ad3f06d8703$export$d753131d7d9b4cdb(this.value);
const formatter = (0, $b8f6b02ccb3471cd$exports.getFromCache)($daef0ad3f06d8703$var$_WeekFormatterCache, Intl.NumberFormat, undefined, options);
return formatter.format(isoWeek.week) + (this.props.displayYear ? "/" + formatter.format(isoWeek.year) : "");
} else return "";
}
}
function $daef0ad3f06d8703$export$d753131d7d9b4cdb(inputDate) {
const purifiedDate = new Date(inputDate.getTime());
// Remove Time part of the Date value
purifiedDate.setHours(0, 0, 0, 0);
// Thursday in current week decides the year.
const thursday = purifiedDate;
// This is the four-digit year corresponding to the input ISO week of the date.
const year = $daef0ad3f06d8703$var$calcYearOfISOCalendarWeek(thursday);
// January 4 is always in week 1.
const fourthOfJanuaryWeek = new Date(year, 0, 4);
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
const week = 1 + Math.round(((thursday.getTime() - fourthOfJanuaryWeek.getTime()) / 86400000 - 3 + (fourthOfJanuaryWeek.getDay() + 6) % 7) / 7);
return {
week: week,
year: year
};
}
// Returns the four-digit year corresponding to the ISO week of the date.
function $daef0ad3f06d8703$var$calcYearOfISOCalendarWeek(inputDate) {
const purifiedDate = new Date(inputDate.getTime());
// Thursday in current week decides the year.
purifiedDate.setDate(purifiedDate.getDate() + 3 - (purifiedDate.getDay() + 6) % 7);
// console.log("4", purifiedDate);
return purifiedDate.getFullYear();
}
//# sourceMappingURL=WeekRenderer.6268b6e4.js.map