MCPcopy Index your code
hub / github.com/Lobos/react-ui / format

Function format

src/utils/datetime.js:106–134  ·  view source on GitHub ↗
(date, fmt)

Source from the content-addressed store, hash-verified

104}
105
106export function format (date, fmt) {
107 if (!date) { return ''; }
108 if (!(date instanceof Date)) {
109 date = convert(date);
110 }
111
112 if (isNaN(date.getTime())) {
113 return 'Invalid Date';
114 }
115
116 let o = {
117 'M+': date.getMonth() + 1,
118 'd+': date.getDate(),
119 'h+': date.getHours(),
120 'm+': date.getMinutes(),
121 's+': date.getSeconds(),
122 'q+': Math.floor((date.getMonth() + 3) / 3),
123 'S': date.getMilliseconds()
124 };
125 if (/(y+)/.test(fmt)) {
126 fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
127 }
128 for (let k in o) {
129 if (new RegExp('(' + k + ')').test(fmt)) {
130 fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
131 }
132 }
133 return fmt;
134}
135
136export function getDatetime (d) {
137 return format(d, getLang('datetime.format.datetime'));

Callers 4

getDatetimeFunction · 0.70
getDateFunction · 0.70
getFullYearFunction · 0.70
getTimeFunction · 0.70

Calls 2

convertFunction · 0.85
getTimeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…