✨ Enrich user profile settings
This commit is contained in:
18
lib/services/time.dart
Normal file
18
lib/services/time.dart
Normal file
@ -0,0 +1,18 @@
|
||||
extension DurationFormatter on Duration {
|
||||
String formatDuration() {
|
||||
final isNegative = inMicroseconds < 0;
|
||||
final positiveDuration = isNegative ? -this : this;
|
||||
|
||||
final hours = positiveDuration.inHours.toString().padLeft(2, '0');
|
||||
final minutes = (positiveDuration.inMinutes % 60).toString().padLeft(
|
||||
2,
|
||||
'0',
|
||||
);
|
||||
final seconds = (positiveDuration.inSeconds % 60).toString().padLeft(
|
||||
2,
|
||||
'0',
|
||||
);
|
||||
|
||||
return '${isNegative ? '-' : ''}$hours:$minutes:$seconds';
|
||||
}
|
||||
}
|
1
lib/services/timezone.dart
Normal file
1
lib/services/timezone.dart
Normal file
@ -0,0 +1 @@
|
||||
export 'timezone/native.dart' if (dart.library.html) 'timezone/web.dart';
|
22
lib/services/timezone/native.dart
Normal file
22
lib/services/timezone/native.dart
Normal file
@ -0,0 +1,22 @@
|
||||
import 'package:flutter_timezone/flutter_timezone.dart';
|
||||
import 'package:timezone/standalone.dart' as tz;
|
||||
import 'package:timezone/data/latest_all.dart' as tzdb;
|
||||
|
||||
Future<void> initializeTzdb() async {
|
||||
tzdb.initializeTimeZones();
|
||||
}
|
||||
|
||||
(Duration offset, DateTime now) getTzInfo(String name) {
|
||||
final location = tz.getLocation(name);
|
||||
final now = tz.TZDateTime.now(location);
|
||||
final offset = now.timeZoneOffset;
|
||||
return (offset, now);
|
||||
}
|
||||
|
||||
Future<String> getMachineTz() async {
|
||||
return await FlutterTimezone.getLocalTimezone();
|
||||
}
|
||||
|
||||
List<String> getAvailableTz() {
|
||||
return tz.timeZoneDatabase.locations.keys.toList();
|
||||
}
|
21
lib/services/timezone/web.dart
Normal file
21
lib/services/timezone/web.dart
Normal file
@ -0,0 +1,21 @@
|
||||
import 'package:flutter_timezone/flutter_timezone.dart';
|
||||
import 'package:timezone/browser.dart' as tz;
|
||||
|
||||
Future<void> initializeTzdb() async {
|
||||
await tz.initializeTimeZone();
|
||||
}
|
||||
|
||||
(Duration offset, DateTime now) getTzInfo(String name) {
|
||||
final location = tz.getLocation(name);
|
||||
final now = tz.TZDateTime.now(location);
|
||||
final offset = now.timeZoneOffset;
|
||||
return (offset, now);
|
||||
}
|
||||
|
||||
Future<String> getMachineTz() async {
|
||||
return await FlutterTimezone.getLocalTimezone();
|
||||
}
|
||||
|
||||
List<String> getAvailableTz() {
|
||||
return tz.timeZoneDatabase.locations.keys.toList();
|
||||
}
|
Reference in New Issue
Block a user