Skip to content

Instantly share code, notes, and snippets.

@wilfrem
Created July 29, 2022 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilfrem/f150f4d12b85339d8800c87b09aeeb0b to your computer and use it in GitHub Desktop.
Save wilfrem/f150f4d12b85339d8800c87b09aeeb0b to your computer and use it in GitHub Desktop.
expire test
void main() async {
final now = DateTime.parse("2022-07-09 12:02:00");
final expirationTime1 = DateTime.parse("2022-07-09 12:03:00");
final expirationTime2 = DateTime.parse("2022-07-09 12:01:00");
final n = now.add(const Duration(minutes: -2)); // 2min前
final n2 = now.add(const Duration(minutes: 2)); // 2min前(修正版)
if (n.isBefore(expirationTime1)) {
print("not expired1");
} else {
print("expired1");
}
if (n.isBefore(expirationTime2)) {
print("not expired2");
} else {
print("expired2");
}
if (n2.isBefore(expirationTime1)) {
print("not expired3");
} else {
print("expired3");
}
if (n2.isBefore(expirationTime2)) {
print("not expired4");
} else {
print("expired4");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment