Skip to content
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

[Feature Request] New methods on DateTime (firstDayOfMonth, lastDayOfMonth, lastDayOfWeek, firstDayOfWeek, firstDayOfYear, lastDayOfYear) #50

Closed
FMorschel opened this issue May 3, 2022 · 0 comments · Fixed by #51

Comments

@FMorschel
Copy link
Collaborator

Looking for lastDayOfMonth like feature, found this StackOverflow question and I really liked the way Yogesh Parwani mixed Chris Buckett and Kai Sellgren awnsers. As pointed by Juniper Belmont on Buckett's answer, I do think this could be a new feature as mnordine suggested here.

(Better code from here - lrhn)

Code bellow:

extension DateTimeFirstLast on DateTime {
  DateTime get firstDayOfWeek => DateTime.utc(year, month, day + 1 - weekday);
  DateTime get lastDayOfWeek => DateTime.utc(year, month, day + 7 - weekday);  
  DateTime get firstDayOfMonth => DateTime.utc(year, month, 1);
  DateTime get lastDayOfMonth => DateTime.utc(year, month + 1, 0);
  DateTime get firstDayOfYear => DateTime.utc(year, 1, 1);
  DateTime get lastDayOfYear => DateTime.utc(year, 12, 31);
}
@FMorschel FMorschel changed the title New methods on DateTime (firstDayOfMonth, lastDayOfMonth, lastDayOfWeek, firstDayOfWeek, firstDayOfYear, lastDayOfYear) [Feature Request] New methods on DateTime (firstDayOfMonth, lastDayOfMonth, lastDayOfWeek, firstDayOfWeek, firstDayOfYear, lastDayOfYear) May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant