Skip to content

Commit

Permalink
solve issue with toLocaleString on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
anchetaWern authored Apr 23, 2018
1 parent 0752375 commit f61252c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions app/lib/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ function renderItem({item}) {
);
}

function getLocalDateTime(date) {

let hours = date.getHours();
if (hours < 10) hours = '0' + hours;

let minutes = date.getMinutes();
if (minutes < 10) minutes = '0' + minutes;

return date.getMonth() + '/' + date.getDate() + '/' +
date.getFullYear() + ', ' + hours + ':' + minutes;
}

function getShortMonth(month_number) {
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct", "Nov", "Dec"];
return months[month_number + 1];
}

function renderPickerItems(data) {
return data.map((item) => {
let val = item.name.toLowerCase();
Expand All @@ -27,7 +44,7 @@ function uniqid() {
}

function getDate() {
let datetime = new Date().toLocaleString();
let datetime = getLocalDateTime(new Date());
let date = datetime.substr(0, datetime.lastIndexOf(','));
return date;
}
Expand All @@ -37,12 +54,12 @@ function lastWeeksDates () {
for(let i = 0; i < 7; i++){
let d = new Date();
d.setDate(d.getDate() - i);
let datetime = d.toLocaleString();
let datetime = getLocalDateTime(d);
let formatted_date = datetime.substr(0, datetime.lastIndexOf(','));
dates.push(formatted_date);
}

return dates;
}

export { renderItem, renderPickerItems, uniqid, getDate, lastWeeksDates };
export { renderItem, renderPickerItems, uniqid, getDate, lastWeeksDates };

0 comments on commit f61252c

Please sign in to comment.