-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from thaidmfinnick/develop
build: draft
- Loading branch information
Showing
7 changed files
with
354 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,28 @@ | ||
import 'package:intl/intl.dart'; | ||
|
||
extension DateOnlyCompare on DateTime { | ||
bool isSameDate(DateTime other) { | ||
return year == other.year && month == other.month && day == other.day; | ||
} | ||
bool isLowerDate(DateTime other) { | ||
return year < other.year || month < other.month || day < other.day; | ||
} | ||
bool isBiggerDate(DateTime other) { | ||
return year > other.year || month > other.month || day > other.day; | ||
} | ||
int get weekNumber { | ||
int dayOfYear = int.parse(DateFormat("D").format(this)); | ||
int woy = ((dayOfYear - weekday + 10) / 7).ceil(); | ||
if (woy < 1) { | ||
woy = _numOfWeeks(year - 1); | ||
} else if (woy > _numOfWeeks(year)) { | ||
woy = 1; | ||
} | ||
return woy; | ||
} | ||
int _numOfWeeks(int year) { | ||
DateTime dec28 = DateTime(year, 12, 28); | ||
int dayOfDec28 = int.parse(DateFormat("D").format(dec28)); | ||
return ((dayOfDec28 - dec28.weekday + 10) / 7).ceil(); | ||
} | ||
} |
Oops, something went wrong.