UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

28 lines (27 loc) 1.15 kB
export var isoToDisplay = function (value) { return value.replace(/-/g, '/'); }; export var displayToIso = function (value) { return value.replace(/\//g, '-'); }; export var daysInMonth = function (date) { return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(); }; var padLeftZeros = function (value, length) { while (value.length < length) { value = "0" + value; } return value; }; export var parseDate = function (value) { var _a = value.split('-'), year = _a[0], month = _a[1], day = _a[2]; return new Date(Number(year), (Number(month) || 1) - 1, Number(day) || 1); }; export var formatDate = function (value) { var year = value.getFullYear(); var month = padLeftZeros("" + (value.getMonth() + 1), 2); var date = padLeftZeros("" + value.getDate(), 2); return year + "-" + month + "-" + date; }; var memoCache = {}; export var memoizedDate = function (key, date) { var parsed = date && date.length >= 4 && parseDate(date); if (!(memoCache[key] && parsed && memoCache[key].getTime() === parsed.getTime())) { memoCache[key] = parsed; } return memoCache[key]; };