@barchart/common-js
Version:
Library of common JavaScript utilities
84 lines (82 loc) • 2.22 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var date_exports = {};
__export(date_exports, {
getDate: () => getDate,
getDateOrdinal: () => getDateOrdinal,
getShortDay: () => getShortDay,
getShortMonth: () => getShortMonth,
getTimestamp: () => getTimestamp,
getYear: () => getYear
});
module.exports = __toCommonJS(date_exports);
function getTimestamp() {
return (/* @__PURE__ */ new Date()).getTime();
}
function getShortDay(date) {
const day = date.getDay();
return days[day].short;
}
function getDate(date) {
return date.getDate();
}
function getDateOrdinal(date) {
const d = getDate(date);
const remainder = d % 10;
let returnRef;
if (remainder === 1 && d !== 11) {
returnRef = "st";
} else if (remainder === 2 && d !== 12) {
returnRef = "nd";
} else if (remainder === 3 && d !== 13) {
returnRef = "rd";
} else {
returnRef = "th";
}
return returnRef;
}
function getShortMonth(date) {
const month = date.getMonth();
return months[month].short;
}
function getYear(date) {
return date.getFullYear();
}
const days = [
{ short: "Sun" },
{ short: "Mon" },
{ short: "Tue" },
{ short: "Wed" },
{ short: "Thu" },
{ short: "Fri" },
{ short: "Sat" }
];
const months = [
{ short: "Jan" },
{ short: "Feb" },
{ short: "Mar" },
{ short: "Apr" },
{ short: "May" },
{ short: "Jun" },
{ short: "Jul" },
{ short: "Aug" },
{ short: "Sep" },
{ short: "Oct" },
{ short: "Nov" },
{ short: "Dec" }
];