@sildeswj/common-libraries
Version:
This is common libraries used for all refeed projects
52 lines • 2.59 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTodayByCountry = exports.getTomorrow = exports.getThisMonth = exports.getThisYear = exports.getToday = exports.getDayjsDate = exports.getStartAndEndDateFromYearAndMonth = exports.getEndDate = exports.getStartDate = exports.userLocale = void 0;
const dayjs_1 = __importDefault(require("dayjs"));
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
const constants_1 = require("./constants");
dayjs_1.default.extend(utc_1.default);
dayjs_1.default.extend(timezone_1.default);
exports.userLocale = Intl.DateTimeFormat().resolvedOptions().locale;
const getStartDate = (date) => (0, dayjs_1.default)(date).locale(exports.userLocale).startOf('day').utc().format();
exports.getStartDate = getStartDate;
const getEndDate = (date) => (0, dayjs_1.default)(date).locale(exports.userLocale).endOf('day').utc().format();
exports.getEndDate = getEndDate;
const getStartAndEndDateFromYearAndMonth = (year, month) => {
const startDate = (0, dayjs_1.default)()
.locale(exports.userLocale)
.year(year)
.month(month - 1)
.startOf('month')
.utc()
.format();
const endDate = (0, dayjs_1.default)()
.locale(exports.userLocale)
.year(year)
.month(month - 1)
.endOf('month')
.utc()
.format();
return { startDate, endDate };
};
exports.getStartAndEndDateFromYearAndMonth = getStartAndEndDateFromYearAndMonth;
const getDayjsDate = (date) => (0, dayjs_1.default)(date).locale(exports.userLocale);
exports.getDayjsDate = getDayjsDate;
const getToday = () => (0, dayjs_1.default)().locale(exports.userLocale).utc().format();
exports.getToday = getToday;
const getThisYear = () => (0, dayjs_1.default)().locale(exports.userLocale).year();
exports.getThisYear = getThisYear;
const getThisMonth = () => (0, dayjs_1.default)().locale(exports.userLocale).month() + 1;
exports.getThisMonth = getThisMonth;
const getTomorrow = () => (0, dayjs_1.default)().locale(exports.userLocale).add(1, 'day').utc().format();
exports.getTomorrow = getTomorrow;
const getTodayByCountry = (countryCode) => {
const tz = constants_1.COUNTRY_TIME_ZONES[countryCode] || 'UTC';
const now = (0, dayjs_1.default)().tz(tz);
return now;
};
exports.getTodayByCountry = getTodayByCountry;
//# sourceMappingURL=dateFormat.js.map