50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
import Theme from "../components/theme.style";
|
|
|
|
const months = [
|
|
{name: 'January', idnumber: "01"},
|
|
{name: 'February', idnumber: "02"},
|
|
{name: 'March', idnumber: "03"},
|
|
{name: 'April', idnumber: "04"},
|
|
{name: 'May', idnumber: "05"},
|
|
{name: 'June', idnumber: "06"},
|
|
{name: 'July', idnumber: "07"},
|
|
{name: 'August', idnumber: "08"},
|
|
{name: 'September', idnumber: "09"},
|
|
{name: 'October', idnumber: "10"},
|
|
{name: 'November', idnumber: "11"},
|
|
{name: 'December', idnumber: "12"},
|
|
]
|
|
|
|
const dateFormater = (date) => {
|
|
if(!date) return;
|
|
|
|
return date.replace(',', '');
|
|
}
|
|
|
|
const dateFormaterForAndroid = (date) => {
|
|
const newSplicedDate = date.replace(',', '').split(' ');
|
|
const item = months.find(month => month.name === newSplicedDate[0]);
|
|
if(item) {
|
|
return `${newSplicedDate[2]}-${item.idnumber}-${newSplicedDate[1]}`
|
|
}
|
|
}
|
|
|
|
const fullDateFormater = (value) => {
|
|
const months = ["Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
|
|
const dates = Theme.platform === "android" ? Date(value) : new Date(value);
|
|
const hour = dates.getHours() < 10 ? `0${dates.getHours()}` : dates.getHours()
|
|
const minute = dates.getMinutes() < 10 ? `0${dates.getMinutes()}` : dates.getMinutes();
|
|
const AMPM = dates.getHours() < 13 ? 'AM' : "PM";
|
|
const date = dates.getDate();
|
|
const month = dates.getMonth();
|
|
const year = dates.getFullYear();
|
|
const newDate = `${months[month]} ${date}, ${year} ${hour}:${minute} ${AMPM}`;
|
|
|
|
return newDate;
|
|
}
|
|
|
|
export {
|
|
fullDateFormater,
|
|
dateFormater,
|
|
dateFormaterForAndroid
|
|
} |