@appscode/design-system
Version:
A design system for Appscode websites and dashboards made using Bulma
45 lines (40 loc) • 1.21 kB
JavaScript
import moment from "moment";
const getTime = (option) => {
if (parseInt(option.time, 10) < 0 || !option.time) {
return undefined;
}
let time = option.time;
// moment(option.time).valueOf('x') needs to convert pharmer's api date to epoch time
time = moment(option.time).valueOf("x") ? moment(option.time).valueOf("x") : time * 1000;
return moment(time).format("MMM DD YYYY, h:mm A");
};
const getDayDifferences = (options) => {
const past = moment(options.past).isValid() ? moment(options.past).valueOf("x") / 1000 : options.past;
const now = Date.now() / 1000;
const diff = now - past;
if (parseInt(options.past, 10) > 10) {
let ret = Math.floor(diff / 86400);
let unit = "";
if (diff < 60) {
ret = parseInt(diff, 10);
unit = " Second";
} else if (diff < 3600) {
ret = parseInt(diff / 60, 10);
unit = " Minute";
} else if (diff < 86400) {
ret = parseInt(diff / 3600, 10);
unit = " Hour";
} else {
ret = parseInt(diff / 86400, 10);
unit = " Day";
}
unit += ret > 1 ? "s" : "";
return ret + unit;
}
return undefined;
};
export default {
getTime,
// formatMoment,
getDayDifferences,
};