Skip to content

Commit

Permalink
solve issue with toLocateString in Android: facebook/react-native#16867
Browse files Browse the repository at this point in the history
- replace with a function which does the same thing
  • Loading branch information
anchetaWern committed Apr 23, 2018
1 parent bd19d05 commit 40a284c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
27 changes: 22 additions & 5 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,13 +44,13 @@ function uniqid() {
}

function getDate() {
let datetime = new Date().toLocaleString();
let datetime = getLocalDateTime(new Date());
let date = datetime.substr(0, datetime.lastIndexOf(','));
return date;
}

function getPathSafeDatetime() {
let datetime = new Date().toLocaleString().replace(/\//g, '-').replace(',', '').replace(/:/g, '_').replace(/ /g, '+');
let datetime = getLocalDateTime(new Date()).replace(/\//g, '-').replace(',', '').replace(/:/g, '_').replace(/ /g, '+');
return datetime;
}

Expand All @@ -42,7 +59,7 @@ 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);
}
Expand All @@ -52,8 +69,8 @@ function lastWeeksDates () {

function friendlyDate(str) {
let friendly_date = str.replace(/-/g, '/').replace(/\+/g, ' ').replace(/_/g, ':');
return friendly_date.substr(0, friendly_date.lastIndexOf(':')) + friendly_date.substr(friendly_date.lastIndexOf(' '));
return friendly_date;
}


export { renderItem, renderPickerItems, uniqid, getDate, lastWeeksDates, getPathSafeDatetime, friendlyDate };
export { renderItem, renderPickerItems, uniqid, getDate, lastWeeksDates, getPathSafeDatetime, friendlyDate, getShortMonth };
5 changes: 3 additions & 2 deletions app/screens/Logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import AlertBox from '../components/AlertBox';

import list_styles from '../components/List/styles';

import { getDate, lastWeeksDates, uniqid } from '../lib/general';
import { getDate, lastWeeksDates, uniqid, getShortMonth } from '../lib/general';

export default class Logs extends React.Component {

Expand Down Expand Up @@ -35,6 +35,7 @@ export default class Logs extends React.Component {

componentDidMount() {
let dates = lastWeeksDates();

let keys = dates.map((date) => {
return date + '_exercises';
});
Expand All @@ -55,7 +56,7 @@ export default class Logs extends React.Component {

let d = new Date(date);

let month = d.toLocaleString('en-us', {month: 'short'});
let month = getShortMonth(d.getMonth());
let day = d.getDate();

logs_data.push({
Expand Down

0 comments on commit 40a284c

Please sign in to comment.