Files
lunasea/lib/core/extensions/duration.dart
Jagandeep Brar 8ecc7e469b fix(navbar): Revert Navigation Bar to Original (#558)
* fix(navbar): Utilize Material 2 Nav Bar

* fix(navbar): Revert to original navigation bar
2022-01-04 21:50:27 -05:00

34 lines
1.2 KiB
Dart

import 'package:lunasea/core.dart';
extension DurationExtension on Duration {
/// Return a string representation of the timestamp.
/// `HH:MM:SS` or `MM:SS` if the duration is less than one hour.
String get lunaTimestamp {
return [
if (this.inHours != 0) this.inHours.toString().padLeft(2, '0'),
(this.inMinutes % 60).toString().padLeft(2, '0'),
(this.inSeconds % 60).toString().padLeft(2, '0'),
].join(':');
}
/// Returns a string representation of the timestamp as words.
///
/// Format example: 1 Day, 23 Hours, 10 Minutes
String get lunaTimestampWords {
String? days, hours, minutes;
if (this.inDays == 1) days = '1 Day';
if (this.inDays > 1) days = '${this.inDays.toString()} Days';
if (this.inHours == 1) hours = '1 Hour';
if (this.inHours > 1) hours = '${(this.inHours % 24).toString()} Hours';
if (this.inMinutes == 1) minutes = '1 Minute';
if (this.inMinutes > 1)
minutes = '${(this.inMinutes % 60).toString()} Minutes';
return [
if (days != null) days,
if (hours != null) hours,
if (minutes != null) minutes,
if (minutes == null) LunaUI.TEXT_EMDASH,
].join(' ');
}
}