diff --git a/components/chart/chart.js b/components/chart/chart.js index df0b52a8751969c0814daab93eb65d652556261b..586ed4166b565b41775dccd2b17b2b3610685a29 100644 --- a/components/chart/chart.js +++ b/components/chart/chart.js @@ -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)) - - return range(earlierDate, today).reverse() + const today = LocalDate.now() + const targetDate = today.minusDays(n) + + 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, []) } diff --git a/package-lock.json b/package-lock.json index df1788c3f3a7dedc46c310587b1f1ab9345265a4..a2ea7950be81f95904c33c1d4959069a06ea720e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index a87b8f9f6391bd4f596d8e3d419d0cc76545b854..ce863237b63ba5b459de02b2467313361cc9150c 100644 --- a/package.json +++ b/package.json @@ -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",