Use LocalDate for getting chart date range
This commit is contained in:
+15
-16
@@ -1,6 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import { View, FlatList, ActivityIndicator } from 'react-native'
|
||||
import range from 'date-range'
|
||||
import { LocalDate } from 'js-joda'
|
||||
import { makeYAxisLabels, makeHorizontalGrid } from './y-axis'
|
||||
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
|
||||
amountOfCycleDays += 5
|
||||
}
|
||||
const jsDates = getTodayAndPreviousDays(amountOfCycleDays)
|
||||
return jsDates.map(jsDate => {
|
||||
return LocalDate.of(
|
||||
jsDate.getFullYear(),
|
||||
jsDate.getMonth() + 1,
|
||||
jsDate.getDate()
|
||||
).toString()
|
||||
})
|
||||
const localDates = getTodayAndPreviousDays(amountOfCycleDays)
|
||||
return localDates.map(localDate => localDate.toString())
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -213,12 +206,18 @@ function LoadingMoreView(props) {
|
||||
}
|
||||
|
||||
function getTodayAndPreviousDays(n) {
|
||||
const today = new Date()
|
||||
today.setHours(12)
|
||||
today.setMinutes(0)
|
||||
today.setSeconds(0)
|
||||
today.setMilliseconds(0)
|
||||
const earlierDate = new Date(today - (range.DAY * n))
|
||||
const today = LocalDate.now()
|
||||
const targetDate = today.minusDays(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, [])
|
||||
}
|
||||
|
||||
Generated
-5
@@ -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": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
"ajv": "^5.5.2",
|
||||
"assert": "^1.4.1",
|
||||
"csvtojson": "^2.0.8",
|
||||
"date-range": "0.0.2",
|
||||
"isobject": "^3.0.1",
|
||||
"js-base64": "^2.4.8",
|
||||
"js-joda": "^1.8.2",
|
||||
|
||||
Reference in New Issue
Block a user