Skip to content

Commit

Permalink
fix(VCalendar): event ends midnight (#11159) (#11168)
Browse files Browse the repository at this point in the history
fixes #11159
  • Loading branch information
ClickerMonkey committed Apr 21, 2020
1 parent faafdec commit ab86223
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('events.ts', () => {
expect(isEventOn(parsed, getDayIdentifier(parseTimestamp('2019-02-12')))).toBeFalsy()
expect(isEventOn(parsed, getDayIdentifier(parseTimestamp('2019-02-13')))).toBeTruthy()
expect(isEventOn(parsed, getDayIdentifier(parseTimestamp('2019-02-14')))).toBeTruthy()
expect(isEventOn(parsed, getDayIdentifier(parseTimestamp('2019-02-15')))).toBeTruthy()
expect(isEventOn(parsed, getDayIdentifier(parseTimestamp('2019-02-15')))).toBeFalsy()
expect(isEventOn(parsed, getDayIdentifier(parseTimestamp('2019-02-16')))).toBeFalsy()
})

Expand Down
5 changes: 4 additions & 1 deletion packages/vuetify/src/components/VCalendar/util/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
parseTimestamp,
getDayIdentifier,
getTimestampIdentifier,
OFFSET_TIME,
} from './timestamp'
import { CalendarTimestamp, CalendarEvent, CalendarEventParsed } from 'types'

Expand All @@ -19,7 +20,9 @@ export function parseEvent (input: CalendarEvent, index: number, startProperty:
}

export function isEventOn (event: CalendarEventParsed, dayIdentifier: number): boolean {
return dayIdentifier >= event.startIdentifier && dayIdentifier <= event.endIdentifier
return dayIdentifier >= event.startIdentifier &&
dayIdentifier <= event.endIdentifier &&
dayIdentifier * OFFSET_TIME !== event.endTimestampIdentifier
}

export function isEventStart (event: CalendarEventParsed, day: CalendarTimestamp, dayIdentifier: number, firstWeekday: number): boolean {
Expand Down
10 changes: 7 additions & 3 deletions packages/vuetify/src/components/VCalendar/util/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const DAYS_IN_WEEK = 7
export const MINUTES_IN_HOUR = 60
export const HOURS_IN_DAY = 24
export const FIRST_HOUR = 0
export const OFFSET_YEAR = 10000
export const OFFSET_MONTH = 100
export const OFFSET_HOUR = 100
export const OFFSET_TIME = 10000

type CalendarTimestampFormatOptions = (timestamp: CalendarTimestamp, short: boolean) => object
type CalendarTimestampOperation = (timestamp: CalendarTimestamp) => CalendarTimestamp
Expand Down Expand Up @@ -151,15 +155,15 @@ export function parseDate (date: Date): CalendarTimestamp {
}

export function getDayIdentifier (timestamp: { year: number, month: number, day: number }): number {
return timestamp.year * 10000 + timestamp.month * 100 + timestamp.day
return timestamp.year * OFFSET_YEAR + timestamp.month * OFFSET_MONTH + timestamp.day
}

export function getTimeIdentifier (timestamp: { hour: number, minute: number }): number {
return timestamp.hour * 100 + timestamp.minute
return timestamp.hour * OFFSET_HOUR + timestamp.minute
}

export function getTimestampIdentifier (timestamp: CalendarTimestamp): number {
return getDayIdentifier(timestamp) * 10000 + getTimeIdentifier(timestamp)
return getDayIdentifier(timestamp) * OFFSET_TIME + getTimeIdentifier(timestamp)
}

export function updateRelative (timestamp: CalendarTimestamp, now: CalendarTimestamp, time = false): CalendarTimestamp {
Expand Down

0 comments on commit ab86223

Please sign in to comment.