@haravan-tech/util
Version:
utilities
37 lines (32 loc) • 727 B
JavaScript
/**
* @namespace date
* @memberof util
*/
;
const _ = require('lodash');
module.exports = {
nowLS, isValidDate
};
/**
* Get current time locale string
* @memberof util.date
* @param {string} [locale]
* @return {string} current time locale string
* @example
* nowLS() => '3/2/2019, 11:48:26 AM'
*/
function nowLS(locale) {
return new Date().toLocaleString(locale);
}
/**
* Check whether val is a valid date
* @memberof util.date
* @param {string|number|Date} val val to check
* @return {boolean}
*/
function isValidDate(val) {
if (_.isString(val) || _.isNumber(val)) {
val = new Date(val);
}
return val instanceof Date && !isNaN(val.getTime());
}