Comments (1)
I like it. Some thoughts/caveats:
-
This type of component is hard to implement correctly with keyboard shortcuts and accessibility. Having helper functions for this specific use case might encourage inexperienced users to tackle this from scratch instead of using a properly tested library.
-
Not all calendar views render a fixed 6 weeks, see the month view on the web version of Google Calendar or MUI's date picker / calendar for example. There are UX trade-offs: a stable grid between months vs more vertical space to display information or events. Most months can fit in a 5 weeks layout.
-
If we're looking at the 6 weeks layout, the solution is simpler than described since the end date will always be 41 days (6 weeks - 1 day) after the start of the month "sheet". You don't need to explicitly know when the month ends.
-
ISO weeks always start on Monday and thus are not localizable. They should probably not be used for a user-centric calendar display unless it's part of the requirements.
For reference :
// process.env.TZ = 'Europe/Berlin';
import { addDays, endOfMonth, endOfWeek, startOfMonth, startOfWeek } from 'date-fns';
import { de } from 'date-fns/locale'; // use a locale or manually set the `weekStartsOn` option on the weeks functions
const today = new Date(2024, 4, 16);
const startOfCalendarSheet = startOfWeek(startOfMonth(today), { locale: de });
const endOfCalendarSheetPadLastWeek = endOfWeek(endOfMonth(today), { locale: de });
const endOfCalendarSheetFixedSixWeeks = addDays(startOfCalendarSheet, 6 * 7 - 1);
console.log(startOfCalendarSheet.toString()); // Mon Apr 29 2024 00:00:00 GMT+0200 (Central European Summer Time)
console.log(endOfCalendarSheetPadLastWeek.toString()); // Sun Jun 02 2024 23:59:59 GMT+0200 (Central European Summer Time)
console.log(endOfCalendarSheetFixedSixWeeks.toString()); // Sun Jun 09 2024 00:00:00 GMT+0200 (Central European Summer Time)
from date-fns.
Related Issues (20)
- when using experimental loader flag, issue with longFormatter being exported twice HOT 2
- WARNING in shared module date-fns-tz
- Why the unpacked size of v3.6.0 is 22.2MB? HOT 3
- Locales dynamic import HOT 6
- `areIntervalsOverlapping` works inconsistently with zero-length intervals. HOT 2
- Problem in startOfDay documentation HOT 2
- `set` not working correctly when hours=0 ?
- All versions since 2.0.0-alpha0 are missing from cdnjs.com HOT 1
- formating MMM for Ru locale was not corrected HOT 1
- Add function to parse RFC822
- CDN minified version incompatible with jQuery HOT 1
- bug: `isMatch` validates "isMatch("20-02-02", "yyyy-MM-dd")"
- `format` typing incorrect for `locale` option
- Support for development on Windows HOT 3
- Problem with formatDuration function HOT 2
- FormatDistance doesn't work the same way for all locales HOT 2
- Typescript/Jest performance issues HOT 2
- roundToNearestMinutes in version 2 is not working as expected
- Add the installation of bun on the contributing guidelines
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from date-fns.