mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-27 22:16:13 +00:00
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
const dateMapping = {
|
|
EU: {
|
|
momentFormat: 'DD/MM/YYYY',
|
|
humanFormat: 'dd/mm/yyyy',
|
|
},
|
|
US: {
|
|
momentFormat: 'MM/DD/YYYY',
|
|
humanFormat: 'mm/dd/yyyy',
|
|
},
|
|
ISO: {
|
|
momentFormat: 'YYYY-MM-DD',
|
|
humanFormat: 'yyyy-mm-dd',
|
|
},
|
|
}
|
|
|
|
const timeMapping = {
|
|
12: {
|
|
momentFormat: 'hh:mm A',
|
|
humanFormat: 'hh:mm AM',
|
|
},
|
|
24: {
|
|
momentFormat: 'HH:mm',
|
|
humanFormat: 'hh:mm',
|
|
},
|
|
}
|
|
|
|
export const getDateMomentFormat = (type) => {
|
|
if (!Object.prototype.hasOwnProperty.call(dateMapping, type)) {
|
|
throw new Error(`${type} wasn't found in the date mapping.`)
|
|
}
|
|
return dateMapping[type].momentFormat
|
|
}
|
|
|
|
export const getTimeMomentFormat = (type) => {
|
|
if (!Object.prototype.hasOwnProperty.call(timeMapping, type)) {
|
|
throw new Error(`${type} wasn't found in the time mapping.`)
|
|
}
|
|
return timeMapping[type].momentFormat
|
|
}
|
|
|
|
export const getDateHumanReadableFormat = (type) => {
|
|
if (!Object.prototype.hasOwnProperty.call(dateMapping, type)) {
|
|
throw new Error(`${type} wasn't found in the date mapping.`)
|
|
}
|
|
return dateMapping[type].humanFormat
|
|
}
|
|
|
|
export const getTimeHumanReadableFormat = (type) => {
|
|
if (!Object.prototype.hasOwnProperty.call(timeMapping, type)) {
|
|
throw new Error(`${type} wasn't found in the time mapping.`)
|
|
}
|
|
return timeMapping[type].humanFormat
|
|
}
|