Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add justTime method #59

Merged
merged 1 commit into from
Nov 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/src/date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,19 @@ class Date {

return '${hour}:${minute} ${timeSuffix}${timeZone}';
}

/// Generates a random time (only digits)
/// Such as 23:52, 06:45, 03:14
String justTime() {
final date = dateTime();
String hour = (date.hour < 10) ? '0' + date.hour.toString() : date.hour.toString();

// If the minute is a single digit (i.e. less than 10)
// We want to prepend a 0 to it.
final minute = (date.minute < 10)
? '0' + date.minute.toString()
: date.minute.toString();

return '${hour}:${minute}';
}
}