Use LocalDate for getting chart date range

This commit is contained in:
Julia Friesel
2019-04-02 19:27:28 +02:00
parent 60d1b3d157
commit 7e3eae1758
3 changed files with 15 additions and 22 deletions
+15 -16
View File
@@ -1,6 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { View, FlatList, ActivityIndicator } from 'react-native' import { View, FlatList, ActivityIndicator } from 'react-native'
import range from 'date-range'
import { LocalDate } from 'js-joda' import { LocalDate } from 'js-joda'
import { makeYAxisLabels, makeHorizontalGrid } from './y-axis' import { makeYAxisLabels, makeHorizontalGrid } from './y-axis'
import nfpLines from './nfp-lines' import nfpLines from './nfp-lines'
@@ -124,14 +123,8 @@ export default class CycleChart extends Component {
// we don't want the chart to end abruptly before the first data day // we don't want the chart to end abruptly before the first data day
amountOfCycleDays += 5 amountOfCycleDays += 5
} }
const jsDates = getTodayAndPreviousDays(amountOfCycleDays) const localDates = getTodayAndPreviousDays(amountOfCycleDays)
return jsDates.map(jsDate => { return localDates.map(localDate => localDate.toString())
return LocalDate.of(
jsDate.getFullYear(),
jsDate.getMonth() + 1,
jsDate.getDate()
).toString()
})
} }
render() { render() {
@@ -213,12 +206,18 @@ function LoadingMoreView(props) {
} }
function getTodayAndPreviousDays(n) { function getTodayAndPreviousDays(n) {
const today = new Date() const today = LocalDate.now()
today.setHours(12) const targetDate = today.minusDays(n)
today.setMinutes(0)
today.setSeconds(0)
today.setMilliseconds(0)
const earlierDate = new Date(today - (range.DAY * n))
return range(earlierDate, today).reverse() function getDaysInRange(currDate, range) {
if (currDate.isBefore(targetDate)) {
return range
} else {
range.push(currDate)
const next = currDate.minusDays(1)
return getDaysInRange(next, range)
}
}
return getDaysInRange(today, [])
} }
-5
View File
@@ -3220,11 +3220,6 @@
} }
} }
}, },
"date-range": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/date-range/-/date-range-0.0.2.tgz",
"integrity": "sha1-OVHZ5SWZgu3VMewx5APYImPvbjk="
},
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
-1
View File
@@ -21,7 +21,6 @@
"ajv": "^5.5.2", "ajv": "^5.5.2",
"assert": "^1.4.1", "assert": "^1.4.1",
"csvtojson": "^2.0.8", "csvtojson": "^2.0.8",
"date-range": "0.0.2",
"isobject": "^3.0.1", "isobject": "^3.0.1",
"js-base64": "^2.4.8", "js-base64": "^2.4.8",
"js-joda": "^1.8.2", "js-joda": "^1.8.2",