class Duration implements Comparable<Duration> {
static const int microsecondsPerMillisecond = 1000;
static const int millisecondsPerSecond = 1000;
static const int secondsPerMinute = 60;
static const int minutesPerHour = 60;
static const int hoursPerDay = 24;
static const int microsecondsPerSecond =
microsecondsPerMillisecond * millisecondsPerSecond;
static const int microsecondsPerMinute =
microsecondsPerSecond * secondsPerMinute;
static const int microsecondsPerHour = microsecondsPerMinute * minutesPerHour;
static const int microsecondsPerDay = microsecondsPerHour * hoursPerDay;
static const int millisecondsPerMinute =
millisecondsPerSecond * secondsPerMinute;
static const int millisecondsPerHour = millisecondsPerMinute * minutesPerHour;
static const int millisecondsPerDay = millisecondsPerHour * hoursPerDay;
static const int secondsPerHour = secondsPerMinute * minutesPerHour;
static const int secondsPerDay = secondsPerHour * hoursPerDay;
static const int minutesPerDay = minutesPerHour * hoursPerDay;
static const Duration zero = Duration(seconds: 0);
final int _duration;
const Duration(
{int days = 0,
int hours = 0,
int minutes = 0,
int seconds = 0,
int milliseconds = 0,
int microseconds = 0})
: this._microseconds(microsecondsPerDay * days +
microsecondsPerHour * hours +
microsecondsPerMinute * minutes +
microsecondsPerSecond * seconds +
microsecondsPerMillisecond * milliseconds +
microseconds);
const Duration._microseconds(this._duration);
Duration operator +(Duration other) {
return Duration._microseconds(_duration + other._duration);
}
Duration operator -(Duration other) {
return Duration._microseconds(_duration - other._duration);
}
Duration operator *(num factor) {
return Duration._microseconds((_duration * factor).round());
}
Duration operator ~/(int quotient) {
if (quotient == 0) throw IntegerDivisionByZeroException();
return Duration._microseconds(_duration ~/ quotient);
}
bool operator <(Duration other) => this._duration < other._duration;
bool operator >(Duration other) => this._duration > other._duration;
bool operator <=(Duration other) => this._duration <= other._duration;
bool operator >=(Duration other) => this._duration >= other._duration;
int get inDays => _duration ~/ Duration.microsecondsPerDay;
int get inHours => _duration ~/ Duration.microsecondsPerHour;
int get inMinutes => _duration ~/ Duration.microsecondsPerMinute;
int get inSeconds => _duration ~/ Duration.microsecondsPerSecond;
int get inMilliseconds => _duration ~/ Duration.microsecondsPerMillisecond;
int get inMicroseconds => _duration;
bool operator ==(Object other) =>
other is Duration && _duration == other.inMicroseconds;
int get hashCode => _duration.hashCode;
int compareTo(Duration other) => _duration.compareTo(other._duration);
String toString() {
String sixDigits(int n) {
if (n >= 100000) return "$n";
if (n >= 10000) return "0$n";
if (n >= 1000) return "00$n";
if (n >= 100) return "000$n";
if (n >= 10) return "0000$n";
return "00000$n";
}
String twoDigits(int n) {
if (n >= 10) return "$n";
return "0$n";
}
if (inMicroseconds < 0) { return "-${-this}"; }
String twoDigitMinutes =
twoDigits(inMinutes.remainder(minutesPerHour) as int);
String twoDigitSeconds =
twoDigits(inSeconds.remainder(secondsPerMinute) as int);
String sixDigitUs =
sixDigits(inMicroseconds.remainder(microsecondsPerSecond) as int);
return "$inHours:$twoDigitMinutes:$twoDigitSeconds.$sixDigitUs";
}
bool get isNegative => _duration < 0;
Duration abs() => Duration._microseconds(_duration.abs());
Duration operator -() => Duration._microseconds(0 - _duration);
}
main(List<String> args) {
print(Duration(milliseconds: -1));
}
@immutable
class Permission {
const Permission._(this.value);
factory Permission.byValue(int value) => values[value];
final int value;
static const calendar = Permission._(0);
static const camera = Permission._(1);
static const contacts = Permission._(2);
static const location = PermissionWithService._(3);
static const locationAlways = PermissionWithService._(4);
static const locationWhenInUse = PermissionWithService._(5);
static const mediaLibrary = Permission._(6);
static const microphone = Permission._(7);
static const phone = PermissionWithService._(8);
static const photos = Permission._(9);
static const photosAddOnly = Permission._(10);
static const reminders = Permission._(11);
static const sensors = Permission._(12);
static const sms = Permission._(13);
static const speech = Permission._(14);
static const storage = Permission._(15);
static const ignoreBatteryOptimizations = Permission._(16);
static const notification = Permission._(17);
static const accessMediaLocation = Permission._(18);
static const activityRecognition = Permission._(19);
static const unknown = Permission._(20);
static const bluetooth = Permission._(21);
static const manageExternalStorage = Permission._(22);
static const systemAlertWindow = Permission._(23);
static const requestInstallPackages = Permission._(24);
static const appTrackingTransparency = Permission._(25);
static const criticalAlerts = Permission._(26);
static const accessNotificationPolicy = Permission._(27);
static const bluetoothScan = Permission._(28);
static const bluetoothAdvertise = Permission._(29);
static const bluetoothConnect = Permission._(30);
static const List<Permission> values = <Permission>[
calendar,
camera,
contacts,
location,
locationAlways,
locationWhenInUse,
mediaLibrary,
microphone,
phone,
photos,
photosAddOnly,
reminders,
sensors,
sms,
speech,
storage,
ignoreBatteryOptimizations,
notification,
accessMediaLocation,
activityRecognition,
unknown,
bluetooth,
manageExternalStorage,
systemAlertWindow,
requestInstallPackages,
appTrackingTransparency,
criticalAlerts,
accessNotificationPolicy,
bluetoothScan,
bluetoothAdvertise,
bluetoothConnect,
];
static const List<String> _names = <String>[
'calendar',
'camera',
'contacts',
'location',
'locationAlways',
'locationWhenInUse',
'mediaLibrary',
'microphone',
'phone',
'photos',
'photosAddOnly',
'reminders',
'sensors',
'sms',
'speech',
'storage',
'ignoreBatteryOptimizations',
'notification',
'access_media_location',
'activity_recognition',
'unknown',
'bluetooth',
'manageExternalStorage',
'systemAlertWindow',
'requestInstallPackages',
'appTrackingTransparency',
'criticalAlerts',
'accessNotificationPolicy',
'bluetoothScan',
'bluetoothAdvertise',
'bluetoothConnect',
];
@override
String toString() => 'Permission.${_names[value]}';
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is Permission && other.value == value;
}
@override
int get hashCode => value.hashCode;
}