Created
February 23, 2025 09:44
-
-
Save PlugFox/4418665f2a328f21b8ff0a40a02796e4 to your computer and use it in GitHub Desktop.
Date object
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
extension type const Date.of(DateTime _date) implements DateTime { | |
Date(int year, int month, int day) : _date = DateTime(year, month, day); | |
Date.now() : _date = DateTime.now(); | |
Date.value(int value) : _date = DateTime((value >> 9), (value >> 5) & 0xF, value & 0x1F); | |
int get value => (_date.year << 9) | (_date.month << 5) | _date.day; | |
} | |
void main() { | |
print(Date(1, 2, 3).value); | |
print(Date.now().value); | |
print(Date.of(DateTime.now()).value); | |
print(Date.value(Date.now().value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment