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

Cloud support DateTime.isLeapYear #106

Closed
wangbo4020 opened this issue Aug 13, 2020 · 5 comments
Closed

Cloud support DateTime.isLeapYear #106

wangbo4020 opened this issue Aug 13, 2020 · 5 comments

Comments

@wangbo4020
Copy link

Like this

extension DateTimeExtension on DateTime {

  bool get isLeapYear => year % 400 == 0 || year % 100 != 0 && year % 4 == 0;

  int get daysInMonth => _calcDaysInMonth();

  int _calcDaysInMonth() {
    switch (month) {
      case DateTime.january:
      case DateTime.march:
      case DateTime.may:
      case DateTime.july:
      case DateTime.august:
      case DateTime.october:
      case DateTime.december:
        return 31;
      case DateTime.february:
        return isLeapYear ? 29 : 28;
      case DateTime.april:
      case DateTime.june:
      case DateTime.september:
      case DateTime.november:
      default:
        return 30;
    }
  }
}
@simc
Copy link
Owner

simc commented Aug 13, 2020

Why did you close this issue? I think it's a good addition...

@wangbo4020
Copy link
Author

wangbo4020 commented Aug 13, 2020

Haha, thanks, I reopen it.

@wangbo4020 wangbo4020 reopened this Aug 13, 2020
@passsy
Copy link
Collaborator

passsy commented Aug 13, 2020

Shouldn't it better added to time?

@shinriyo
Copy link

how about it?
https://github.com/jogboms/time.dart

@shinayser
Copy link
Contributor

Definetly should be added to the time package.

@passsy passsy closed this as completed Mar 22, 2021
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

No branches or pull requests

5 participants