Skip to content

Commit

Permalink
fix: moment.js to avoid android toLocaleString issues
Browse files Browse the repository at this point in the history
  • Loading branch information
echenley committed Mar 6, 2018
1 parent bd14cdd commit 4c122ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 4 additions & 10 deletions src/components/Chart/Chart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import * as React from 'react'
import moment from 'moment'
import { Dimensions, StyleSheet, Text, View } from 'react-native'
import {
VictoryAxis,
Expand Down Expand Up @@ -139,19 +140,12 @@ class Chart extends React.Component<Props, State> {
// 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')
}}
/>
<VictoryAxis
Expand Down
4 changes: 1 addition & 3 deletions src/components/Controls/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ const styles = StyleSheet.create({
display: 'flex',
justifyContent: 'center',
flexDirection: 'row',
height: 36,
marginTop: 10,
marginBottom: 10,
padding: 10,
},
})

Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5423,6 +5423,10 @@ moment@2.x.x, moment@^2.10.6:
version "2.20.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd"

moment@^2.21.0:
version "2.21.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.21.0.tgz#2a114b51d2a6ec9e6d83cf803f838a878d8a023a"

morgan@~1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.6.1.tgz#5fd818398c6819cba28a7cd6664f292fe1c0bbf2"
Expand Down

0 comments on commit 4c122ee

Please sign in to comment.