@kelvininc/ui-components
Version:
Kelvin UI Components
37 lines (36 loc) • 1.61 kB
JavaScript
import dayjs from "dayjs";
import { CALENDAR_DATE_FORMAT, DATE_FORMAT } from "./absolute-time-picker-dropdown-input.config";
import { isEmpty, isNumber } from "lodash-es";
export const getSingleInputDate = (selectedTime, timezoneName) => {
if (isEmpty(selectedTime)) {
return '';
}
return dayjs(selectedTime[0]).tz(timezoneName).format(DATE_FORMAT);
};
export const getRangeInputValues = (selectedTime, timezoneName) => {
if (isEmpty(selectedTime)) {
return {
from: '',
to: ''
};
}
const [from, to] = selectedTime;
return {
from: isNumber(from) ? dayjs(from).tz(timezoneName).format(DATE_FORMAT) : '',
to: isNumber(to) ? dayjs(to).tz(timezoneName).format(DATE_FORMAT) : ''
};
};
export const getSingleCalendarDate = (inputValue) => {
return isEmpty(inputValue) ? [] : [dayjs(inputValue, DATE_FORMAT).format(CALENDAR_DATE_FORMAT)];
};
export const getRangeCalendarDates = (rangeInputValues) => {
const from = rangeInputValues === null || rangeInputValues === void 0 ? void 0 : rangeInputValues.from;
const to = rangeInputValues === null || rangeInputValues === void 0 ? void 0 : rangeInputValues.to;
if (isEmpty(from) && isEmpty(to))
return [];
if (isEmpty(from) && !isEmpty(to))
return [dayjs(to, DATE_FORMAT).format(CALENDAR_DATE_FORMAT)];
if (!isEmpty(from) && isEmpty(to))
return [dayjs(from, DATE_FORMAT).format(CALENDAR_DATE_FORMAT)];
return [dayjs(from, DATE_FORMAT).format(CALENDAR_DATE_FORMAT), dayjs(to, DATE_FORMAT).format(CALENDAR_DATE_FORMAT)];
};