From 4c122ee88e54081fee8b15f409ecb389577920ec Mon Sep 17 00:00:00 2001 From: Evan Henley Date: Mon, 5 Mar 2018 20:28:14 -0600 Subject: [PATCH] fix: moment.js to avoid android toLocaleString issues https://github.com/facebook/react-native/issues/15717 https://github.com/facebook/react-native/issues/16867 --- package.json | 1 + src/components/Chart/Chart.js | 14 ++++---------- src/components/Controls/Controls.js | 4 +--- yarn.lock | 4 ++++ 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index b1da21a..e12e17e 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "axios": "^0.18.0", "eslint-plugin-jest": "^21.12.3", "expo": "^25.0.0", + "moment": "^2.21.0", "native-base": "^2.3.9", "react": "16.2.0", "react-native": "0.52.0", diff --git a/src/components/Chart/Chart.js b/src/components/Chart/Chart.js index 39a5896..f375f6c 100644 --- a/src/components/Chart/Chart.js +++ b/src/components/Chart/Chart.js @@ -1,6 +1,7 @@ // @flow import * as React from 'react' +import moment from 'moment' import { Dimensions, StyleSheet, Text, View } from 'react-native' import { VictoryAxis, @@ -139,19 +140,12 @@ class Chart extends React.Component { // ticks are >= 24 hours apart if (Math.abs(dates[adjacentIndex] - date) > 1000 * 60 * 60 * 24) { const year = date.getFullYear() - return date.toLocaleString('en-US', { - month: 'short', - day: 'numeric', - year: year !== currentYear ? 'numeric' : undefined, - }) + const format = year !== currentYear ? 'l' : 'MMM D' + return moment(date).format(format) } const showMinutes = date.getMinutes() !== 0 - return date.toLocaleString('en-US', { - hour: 'numeric', - minute: showMinutes ? 'numeric' : undefined, - hour12: true, - }) + return moment(date).format(showMinutes ? 'LT' : 'h A') }} />