Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(calendar): compute cell positions missing end date #2457

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/calendar/src/compute/timeRange.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
timeDays,
timeDay,
timeMonday,
timeTuesday,
timeWednesday,
timeThursday,
timeDays,
timeFriday,
timeMonday,
timeSaturday,
timeSunday,
timeThursday,
timeTuesday,
timeWednesday,
} from 'd3-time'
import { timeFormat } from 'd3-time-format'
import { DateOrString, Weekday } from '../types'
import isDate from 'lodash/isDate'
import { DateOrString, Weekday } from '../types'

// Interfaces
interface ComputeBaseProps {
Expand Down Expand Up @@ -246,8 +246,12 @@ export const computeCellPositions = ({
// we need to determine whether we need to add days to move to correct position
const start = from ? from : data[0].date
const end = to ? to : data[data.length - 1].date
const startDate = isDate(start) ? start : new Date(start)
const endDate = isDate(end) ? end : new Date(end)

// The timeDays function's endDate is exclusive, so we need to add one day
// Also we need to reset the hours using timeDay to fix locale issue
const startDate = timeDay(isDate(start) ? start : new Date(start))
const endDate = timeDay.offset(timeDay(isDate(end) ? end : new Date(end)), 1)

const dateRange = timeDays(startDate, endDate).map(dayDate => {
return {
date: dayDate,
Expand Down
11 changes: 7 additions & 4 deletions packages/generators/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import range from 'lodash/range'
import { timeDay, timeDays } from 'd3-time'
import { timeFormat } from 'd3-time-format'
import random from 'lodash/random'
import range from 'lodash/range'
import shuffle from 'lodash/shuffle'
import { timeDays } from 'd3-time'
import { timeFormat } from 'd3-time-format'
import * as color from './color'
import * as sets from './sets'

Expand Down Expand Up @@ -105,7 +105,10 @@ export const generateCountriesPopulation = (size: number) => {
}

export const generateOrderedDayCounts = (from: Date, to: Date) => {
const days = timeDays(from, to)
const startDate = timeDay(from)
const endDate = timeDay.offset(timeDay(to), 1)

const days = timeDays(startDate, endDate)
const dayFormat = timeFormat('%Y-%m-%d')

return days.map(day => {
Expand Down
Loading