MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / formatDate

Function formatDate

apps/OpenSign/src/utils/widgetUtils.js:254–305  ·  view source on GitHub ↗
(dateObj)

Source from the content-addressed store, hash-verified

252};
253
254export function formatDate(dateObj) {
255 const format = dateObj?.format?.toLowerCase();
256 const date = new Date(dateObj.date);
257
258 // zero-padded day and month
259 const dd = String(date.getDate()).padStart(2, "0");
260 const mm = String(date.getMonth() + 1).padStart(2, "0");
261 const yyyy = date.getFullYear();
262
263 // month names
264 const shortNames = [
265 "Jan",
266 "Feb",
267 "Mar",
268 "Apr",
269 "May",
270 "Jun",
271 "Jul",
272 "Aug",
273 "Sep",
274 "Oct",
275 "Nov",
276 "Dec"
277 ];
278 const longNames = [
279 "January",
280 "February",
281 "March",
282 "April",
283 "May",
284 "June",
285 "July",
286 "August",
287 "September",
288 "October",
289 "November",
290 "December"
291 ];
292 const mmm = shortNames[date.getMonth()];
293 const mmmm = longNames[date.getMonth()];
294
295 // a map of token → replacement
296 const tokens = { yyyy: yyyy, mm: mm, dd: dd, mmm: mmm, mmmm: mmmm };
297
298 // Replace longer tokens first
299 return format
300 .replace(/yyyy/, tokens.yyyy)
301 .replace(/mmmm/, tokens.mmmm)
302 .replace(/mmm/, tokens.mmm)
303 .replace(/mm/, tokens.mm)
304 .replace(/dd/, tokens.dd);
305}
306
307// The getDatePickerDate function retrieves the date in the correct format supported by the DatePicker.
308export const getDatePickerDate = (selectedDate, format = "dd-MM-yyyy") => {

Callers 3

handleDateChangeFunction · 0.90
formatDateListFunction · 0.90
addPreferenceOptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected