-
Notifications
You must be signed in to change notification settings - Fork 0
date picker autocomplete #233
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
Open
IslandRhythms
wants to merge
8
commits into
main
Choose a base branch
from
IslandRhythms/improve-date-search
base: main
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f392a93
date picker autocomplete
IslandRhythms 9402d2c
address Val comments
IslandRhythms 8cd1e73
copilot suggestions
IslandRhythms 7a3a133
resolve conflicts
IslandRhythms 3fae467
new date UI
IslandRhythms af15756
Revert "new date UI"
IslandRhythms 3ad1a04
new custom date picker
IslandRhythms e9ce47c
new custom date picker UI
IslandRhythms 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| 'use strict'; | ||
|
|
||
| function pad2(n) { | ||
| return String(n).padStart(2, '0'); | ||
| } | ||
|
|
||
| function pad3(n) { | ||
| return String(n).padStart(3, '0'); | ||
| } | ||
|
|
||
| /** | ||
| * @param {number} value | ||
| * @param {number} min | ||
| * @param {number} max | ||
| */ | ||
| function clampInt(value, min, max) { | ||
| const n = Math.floor(Number(value)); | ||
| if (Number.isNaN(n)) { | ||
| return min; | ||
| } | ||
| return Math.min(max, Math.max(min, n)); | ||
| } | ||
|
|
||
| /** | ||
| * @param {Date} date | ||
| * @returns {string} YYYY-MM-DDTHH:mm:ss.SSS | ||
| */ | ||
| function dateToDatetimeLocal(date) { | ||
| if (!(date instanceof Date) || Number.isNaN(date.getTime())) { | ||
| return ''; | ||
| } | ||
| return [ | ||
| date.getFullYear(), | ||
| '-', | ||
| pad2(date.getMonth() + 1), | ||
| '-', | ||
| pad2(date.getDate()), | ||
| 'T', | ||
| pad2(date.getHours()), | ||
| ':', | ||
| pad2(date.getMinutes()), | ||
| ':', | ||
| pad2(date.getSeconds()), | ||
| '.', | ||
| pad3(date.getMilliseconds()) | ||
| ].join(''); | ||
| } | ||
|
|
||
| /** | ||
| * @param {Date} date | ||
| * @returns {string} YYYY-MM-DD | ||
| */ | ||
| function dateToDateOnly(date) { | ||
| if (!(date instanceof Date) || Number.isNaN(date.getTime())) { | ||
| return ''; | ||
| } | ||
| return [ | ||
| date.getFullYear(), | ||
| '-', | ||
| pad2(date.getMonth() + 1), | ||
| '-', | ||
| pad2(date.getDate()) | ||
| ].join(''); | ||
| } | ||
|
|
||
| /** | ||
| * @param {unknown} value | ||
| * @returns {Date|null} | ||
| */ | ||
| function parseValueToDate(value) { | ||
| if (value == null || value === '') { | ||
| return null; | ||
| } | ||
| const date = new Date(value); | ||
| if (Number.isNaN(date.getTime())) { | ||
| return null; | ||
| } | ||
| return date; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} localValue - YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.SSS | ||
| * @returns {Date|null} | ||
| */ | ||
| function localStringToDate(localValue) { | ||
| if (!localValue) { | ||
| return null; | ||
| } | ||
| const date = new Date(localValue); | ||
| if (Number.isNaN(date.getTime())) { | ||
| return null; | ||
| } | ||
| return date; | ||
| } | ||
|
|
||
| function isSameDay(a, b) { | ||
| if (!a || !b) { | ||
| return false; | ||
| } | ||
| return ( | ||
| a.getFullYear() === b.getFullYear() | ||
| && a.getMonth() === b.getMonth() | ||
| && a.getDate() === b.getDate() | ||
| ); | ||
| } | ||
|
|
||
| function isSameMonth(date, year, month) { | ||
| return date.getFullYear() === year && date.getMonth() === month; | ||
| } | ||
|
|
||
| /** | ||
| * Build a 6-row calendar grid for the given month (local timezone). | ||
| * @param {number} year | ||
| * @param {number} month - 0-indexed | ||
| * @returns {Array<{ key: string, label: number, date: Date, inMonth: boolean }>} | ||
| */ | ||
| function buildCalendarDays(year, month) { | ||
| const firstOfMonth = new Date(year, month, 1); | ||
| const startOffset = firstOfMonth.getDay(); | ||
| const gridStart = new Date(year, month, 1 - startOffset); | ||
|
|
||
| const days = []; | ||
| for (let i = 0; i < 42; i++) { | ||
| const date = new Date(gridStart.getFullYear(), gridStart.getMonth(), gridStart.getDate() + i); | ||
| days.push({ | ||
| key: `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`, | ||
| label: date.getDate(), | ||
| date, | ||
| inMonth: date.getMonth() === month | ||
| }); | ||
| } | ||
| return days; | ||
| } | ||
|
|
||
| const WEEKDAY_LABELS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']; | ||
|
|
||
| const MONTH_LABELS = [ | ||
| 'January', 'February', 'March', 'April', 'May', 'June', | ||
| 'July', 'August', 'September', 'October', 'November', 'December' | ||
| ]; | ||
|
|
||
| module.exports = { | ||
| pad2, | ||
| pad3, | ||
| clampInt, | ||
| dateToDatetimeLocal, | ||
| dateToDateOnly, | ||
| parseValueToDate, | ||
| localStringToDate, | ||
| isSameDay, | ||
| isSameMonth, | ||
| buildCalendarDays, | ||
| WEEKDAY_LABELS, | ||
| MONTH_LABELS | ||
| }; |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.