-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: calendar core #10
Open
bart-krakowski
wants to merge
128
commits into
TanStack:v0
Choose a base branch
from
bart-krakowski:feat/calendar-core
base: v0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
128 commits
Select commit
Hold shift + click to select a range
169e06d
refactor: update isValidDate return type for improved type safety
bart-krakowski 75cb7b3
refactor: update isValidDate return type for improved type safety
bart-krakowski 5dca8d5
refactor: update isValidDate return type for improved type safety
bart-krakowski e9e4be9
revert: isValidDate util
bart-krakowski d64d04a
feat: useCalendar hook
bart-krakowski 28b4304
test: useCalendar tests
bart-krakowski 28f491c
docs: useCalendar hook
bart-krakowski 468dc26
docs: useCalendar hook
bart-krakowski 0b9bdeb
test: useCalendar tests
bart-krakowski 5b6533e
test: useCalendar tests
bart-krakowski 37effd4
test: overlaping events
bart-krakowski 096f95d
feat(react-time/useCalendar): getCurrentTimeMarkerProps
bart-krakowski 26b0e1e
feat(react-time/useCalendar): getCurrentTimeMarkerProps
bart-krakowski 3cf89c3
feat(react-time/useCalendar): getCurrentTimeMarkerProps
bart-krakowski 4ae3c45
refactor: reducer
bart-krakowski 4009dae
refactor: reducer
bart-krakowski fa3716a
refactor(useCalendar): types
bart-krakowski 131984b
refactor(useCalendar): types
bart-krakowski e542934
refactor: useCalendar reducer
bart-krakowski a149778
refactor: useCalendar reducer
bart-krakowski 28ac64f
refactor: useCalendar reducer
bart-krakowski dfa353a
feat: add the isToday field
bart-krakowski 8742087
feat: add the isToday field
bart-krakowski 3d6f74a
feat: add the isToday field
bart-krakowski d93b29d
docs: useCalendar
bart-krakowski 6432973
feat: useCalendar hook
bart-krakowski 75a445a
cd
bart-krakowski 7536efc
feat: useCalendar hook
bart-krakowski 29d20ae
feat: useCalendar hook
bart-krakowski e37dbf7
feat: useCalendar hook
bart-krakowski d76ddc1
feat: useCalendar hook
bart-krakowski f6b6f29
test: useCalendar
bart-krakowski d9ed5e7
test: useCalendar
bart-krakowski 7b8662b
test: useCalendar
bart-krakowski be2e360
feat: custom reducer
bart-krakowski 4ccd56b
docs: tsdocs
bart-krakowski cc59409
docs: tsdocs
bart-krakowski 8d51b58
docs: tsdocs
bart-krakowski 1e71684
refactor: useCalendar
bart-krakowski e134065
refactor: useCalendar
bart-krakowski f3f47ed
refactor: useCalendar
bart-krakowski 1ee814a
refactor: change viewMode type
bart-krakowski c2419de
refactor: change viewMode type
bart-krakowski 215f722
fix: missing days in view
bart-krakowski 0f05c00
refactor: api
bart-krakowski def6499
refactor: api
bart-krakowski 110e8be
fix: types
bart-krakowski 3333fcb
fix: types
bart-krakowski 492405b
fix: types
bart-krakowski 7bee6b4
fix: types
bart-krakowski 83f0724
docs: useCalendar
bart-krakowski e4fb70a
docs: useCalendar
bart-krakowski e598c20
fix: types
bart-krakowski a9665a7
refactor: add the fillMissingDays argument
bart-krakowski d9e9b88
refactor: add the fillMissingDays argument
bart-krakowski fe13c2c
refactor: add the fillMissingDays argument
bart-krakowski 9f99846
refactor: move utilities to the core package
bart-krakowski 93b519a
fix: getCurrentTimeMarkerProps
bart-krakowski 87544e2
docs: update jsdocs
bart-krakowski b5ae21e
test: useCalendar
bart-krakowski f5bd2b7
refactor: getCurrentTimeMarkerProps
bart-krakowski c03128c
feat: calendar core
bart-krakowski 3c48a5e
feat: calendar core
bart-krakowski 6499475
feat: calendar core
bart-krakowski 2ac6065
docs: calendar core
bart-krakowski a71f5a8
refactor: useCalendar
bart-krakowski 965de14
test: calendar core
bart-krakowski 301d4b8
refactor: useCalendar
bart-krakowski 1324311
refactor: useCalendar
bart-krakowski 042bb13
refactor: useCalendar
bart-krakowski 82c1c87
refactor(useCalendar): types
bart-krakowski f61a99d
refactor: move calendar-related files to the core directory
bart-krakowski 1465e85
refactor: Update CalendarCoreOptions interface in calendar.ts
bart-krakowski 3f4ef79
test: imports
bart-krakowski bff5f34
docs: typo
bart-krakowski 57c547e
refactor: DatePickerCore
bart-krakowski 3dc223d
refactor: weekInfoPolyfill
bart-krakowski 2eabee4
refactor: weekInfoPolyfill
bart-krakowski 564c4e7
refactor: weekInfoPolyfill
bart-krakowski 1a5f193
refactor: weekInfoPolyfill
bart-krakowski 3331c17
refactor: date defaults
bart-krakowski e1f9c12
refactor: date defaults
bart-krakowski 1dfecfb
refactor: date defaults
bart-krakowski 277f416
refactor: types
bart-krakowski 4131b8e
docs: jsdocs
bart-krakowski b7f67f0
refactor: types
bart-krakowski 4165b20
refactor: types
bart-krakowski 1b71c7e
test: useCalendar
bart-krakowski 604c8bb
refactor: useIsomorphicLayoutEffect
bart-krakowski 6311195
docs: calendar
bart-krakowski 6627c0c
docs: calendar
bart-krakowski df925d4
refactor: zonedDateTime
bart-krakowski c65b760
refactor: rename startDate to start and endDate to end
bart-krakowski 18ad00c
refactor: remove the getCurrentTimeMarkerProps method
bart-krakowski 403df99
refactor: weekInfoPolyfill
bart-krakowski a805131
refactor: add a resources field to event
bart-krakowski e17f0cd
refactor: add a resources field to event
bart-krakowski 396d629
refactor: add a resources field to event
bart-krakowski adc9998
refactor: add startOf and endOf helpers
bart-krakowski 31470b4
refactor: remove all the layout specific code
bart-krakowski 16867e8
refactor: update getDaysNames method to accept weekday parameter
bart-krakowski be68798
refactor: update useCalendar test to mock current date and time
bart-krakowski c3ba0c9
refactor: update useCalendar test to mock current date and time
bart-krakowski 5afea3e
test: update useCalendar tests
bart-krakowski 15aced5
test: update useCalendar tests
bart-krakowski eb8b7b7
test: useCalendar
bart-krakowski 4d71196
refactor: update CalendarCore tests to mock current date and time
bart-krakowski fbbae15
refactor: Update CalendarCore to use destructuring assignment for dat…
bart-krakowski ce9b924
feat: add the activeDate property
bart-krakowski 66bfe53
refactor: use compare method
bart-krakowski 06f633d
feat: add workWeek unit
bart-krakowski 0c8c868
feat: add workWeek unit
bart-krakowski 4b7ea40
test: tests reorganisation
bart-krakowski d544348
chore: add the get-week-info-polyfill
bart-krakowski d090483
feat: getWeekInfo polyfill
bart-krakowski 178aa34
refactor: getEventProps
bart-krakowski 79fdfdd
refactor: getEventProps
bart-krakowski 20fb06d
refactor: Update generateDateRange to accept string inputs
bart-krakowski 8ae1bcd
chore: upgrade polyfill
bart-krakowski 0e974ac
fix: getEventProps
bart-krakowski 85c6a77
fix: getEventProps
bart-krakowski 72d43d4
refactor: update date inputs to accept string format
bart-krakowski cbc2186
refactor: convert activeDate, currentPeriod to string in useCalendar
bart-krakowski 1f6048e
refactor: startOf and endOf helpers
bart-krakowski 291cfb1
test: calendar core
bart-krakowski 3aa0488
refactor: update useCalendar to accept string inputs for activeDate a…
bart-krakowski 8850d2a
refactor: Update get-week-info-polyfill dependency to version 1.0.6
bart-krakowski fe67772
refactor: Update startOf and endOf helpers to accept string inputs
bart-krakowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,68 @@ | ||
import type { Temporal } from '@js-temporal/polyfill' | ||
|
||
type ViewUnit = 'month' | 'week' | 'day' | 'workWeek' | 'decade' | 'year' | ||
|
||
interface EndOfParams { | ||
date: Temporal.ZonedDateTime | ||
unit: ViewUnit | ||
viewModeValue?: number | ||
firstDayOfWeek?: number | ||
} | ||
|
||
/** | ||
* Helper function to get the end of a given temporal unit. | ||
* @param date {Temporal.ZonedDateTime} - The date for which the end of the unit is needed. | ||
* @param unit {Unit} - The unit for which to find the end ('day', 'week', 'month', 'year', 'workWeek', 'decade'). | ||
* @param {EndOfParams} params - The parameters for the endOf function. | ||
* @returns {Temporal.ZonedDateTime} The end of the given unit. | ||
*/ | ||
export const endOf = (date: Temporal.ZonedDateTime, unit: 'day' | 'week' | 'month' | 'year' | 'workWeek' | 'decade'): Temporal.ZonedDateTime => { | ||
export function endOf({ | ||
date, | ||
unit, | ||
viewModeValue = 1, | ||
firstDayOfWeek = 1, | ||
}: EndOfParams): Temporal.ZonedDateTime { | ||
let endDate: Temporal.ZonedDateTime | ||
|
||
switch (unit) { | ||
case 'day': | ||
return date.with({ | ||
hour: 23, | ||
minute: 59, | ||
second: 59, | ||
millisecond: 999, | ||
}); | ||
case 'week': { | ||
const endOfWeek = date.add({ days: 7 - date.dayOfWeek }).with({ | ||
hour: 23, | ||
minute: 59, | ||
second: 59, | ||
millisecond: 999, | ||
}); | ||
return endOfWeek; | ||
} | ||
case 'month': { | ||
const lastDayOfMonth = date.with({ day: 1 }).add({ months: 1 }).subtract({ days: 1 }); | ||
return lastDayOfMonth.with({ | ||
hour: 23, | ||
minute: 59, | ||
second: 59, | ||
millisecond: 999, | ||
}); | ||
} | ||
case 'year': { | ||
const lastDayOfYear = date.with({ month: 12, day: 31 }); | ||
return lastDayOfYear.with({ | ||
hour: 23, | ||
minute: 59, | ||
second: 59, | ||
millisecond: 999, | ||
}); | ||
} | ||
case 'workWeek': { | ||
const endOfWorkWeek = date.add({ days: 5 - date.dayOfWeek }).with({ | ||
hour: 23, | ||
minute: 59, | ||
second: 59, | ||
millisecond: 999, | ||
}); | ||
return endOfWorkWeek; | ||
} | ||
endDate = date | ||
break | ||
case 'week': | ||
endDate = date.add({ days: 7 - date.dayOfWeek }) | ||
break | ||
case 'workWeek': | ||
endDate = date.add({ days: 5 - date.dayOfWeek }) | ||
break | ||
case 'month': | ||
endDate = date | ||
.with({ day: 1 }) | ||
.add({ months: viewModeValue }) | ||
.subtract({ days: 1 }) | ||
if (viewModeValue > 1) { | ||
const lastDayOfMonthWeekDay = | ||
(endDate.dayOfWeek - firstDayOfWeek + 7) % 7 | ||
endDate = endDate.add({ days: 6 - lastDayOfMonthWeekDay }) | ||
} | ||
break | ||
case 'year': | ||
endDate = date.with({ month: 12, day: 31 }) | ||
break | ||
case 'decade': { | ||
const lastYearOfDecade = date.with({ year: date.year - (date.year % 10) + 9 }); | ||
const lastDayOfDecade = lastYearOfDecade.with({ month: 12, day: 31 }); | ||
return lastDayOfDecade.with({ | ||
hour: 23, | ||
minute: 59, | ||
second: 59, | ||
millisecond: 999, | ||
}); | ||
const lastYearOfDecade = date.with({ | ||
year: date.year - (date.year % 10) + 9, | ||
}) | ||
endDate = lastYearOfDecade.with({ month: 12, day: 31 }) | ||
break | ||
} | ||
default: | ||
throw new Error(`Unsupported unit: ${unit}`); | ||
throw new Error(`Unsupported unit: ${unit}`) | ||
} | ||
|
||
return endDate.with({ | ||
hour: 23, | ||
minute: 59, | ||
second: 59, | ||
millisecond: 999, | ||
microsecond: 999, | ||
nanosecond: 999, | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the direction here. I started a discussion in the time-maintainers discord around these types of methods...