function that tells if given date is in this week or Not. #3205
-
hey, I am currently working with I have checked I am not sure if there is any function or not. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
@Akhilbisht798 I would like to take up this issue |
Beta Was this translation helpful? Give feedback.
-
@Pooja444 Hey, I am currently new to this project and don't have much experience working on it. I opened this new issue as a suggestion for the people who are more experienced than me in this. |
Beta Was this translation helpful? Give feedback.
-
@Akhilbisht798 I don't think there's a function to specifically handle this use case, but you can easily get there with import { startOfWeek } from "date-fns";
function isDateInCurrentWeek(date) {
return startOfWeek(new Date()).getTime() === startOfWeek(date).getTime();
}
console.log(isDateInCurrentWeek(new Date(2022, 9, 4))); // true
console.log(isDateInCurrentWeek(new Date(2022, 9, 2))); // true
console.log(isDateInCurrentWeek(new Date(2022, 9, 1))); // false @Pooja444 I'm not on the core team, so I can't confirm but there was a recent addition to the README that hints that it will. 9ecc9b2
|
Beta Was this translation helpful? Give feedback.
-
@fturmel hey, your solution is great for this problem. Do I keep this issue open for further discussion on this idea or just close it? |
Beta Was this translation helpful? Give feedback.
-
It's simple enough that I don't think it's adding a lot of value, but since the library is tree-shakable there's no file size penalty for adding more helper functions. You could always work on a PR, but I have no idea if it might get accepted and merged. I'll move this to discussions for now so it'll be easier for the community to find the proposed solution. |
Beta Was this translation helpful? Give feedback.
-
Oh, it will we great to make it into the discussion. |
Beta Was this translation helpful? Give feedback.
@Akhilbisht798 I don't think there's a function to specifically handle this use case, but you can easily get there with
startOfWeek
:@Pooja444 I'm not on the core team, so I can't confirm but there was a recent addition to the README that hints that it will. 9ecc9b2