fix: timezone

release/mobdr-v0.0.1
Frédérik Benoist 2023-06-07 22:32:19 +02:00
parent fbddac5c9c
commit cf394811d2
4 changed files with 25 additions and 3 deletions

View File

@ -21,6 +21,6 @@ class Log {
{this.id = 0, DateTime? date, this.uploaded = 0}) {this.id = 0, DateTime? date, this.uploaded = 0})
: date = date ?? DateTime.now(); : date = date ?? DateTime.now();
String get dateFormat => DateFormat('dd/MM/yyyy hh:mm:ss').format(date); String get dateFormat => DateFormat('dd/MM/yyyy HH:mm:ss').format(date);
String get dateEnFormat => DateFormat('yyyyMMdd hh:mm:ss').format(date); String get dateEnFormat => DateFormat('yyyyMMdd HH:mm:ss').format(date);
} }

View File

@ -48,7 +48,7 @@ class VisitPhoto {
return image_name; return image_name;
} }
String get dateFormat => DateFormat('dd.MM.yyyy hh:mm:ss').format(date_photo); String get dateFormat => DateFormat('dd.MM.yyyy HH:mm:ss').format(date_photo);
VisitPhoto copyWith({ VisitPhoto copyWith({
int? id, int? id,

View File

@ -24,6 +24,18 @@ late ObjectBox objectbox;
final EventBus eventBus = EventBus(); final EventBus eventBus = EventBus();
String getCurrentTimeZone(DateTime dateTime) {
Duration offset = dateTime.timeZoneOffset;
int offsetHours = offset.inHours;
int offsetMinutes = offset.inMinutes.remainder(60);
String offsetSign = offset.isNegative ? '-' : '+';
String timeZone =
'$offsetSign${offsetHours.abs().toString().padLeft(2, '0')}:${offsetMinutes.abs().toString().padLeft(2, '0')}';
return timeZone;
}
Future<void> main() async { Future<void> main() async {
// This is required so ObjectBox can get the application directory // This is required so ObjectBox can get the application directory
// to store the database in. // to store the database in.
@ -49,6 +61,9 @@ Future<void> main() async {
/// initialize tracker plausible analytics /// initialize tracker plausible analytics
await PlausibleUtil.initializePlausible(window.physicalSize.width); await PlausibleUtil.initializePlausible(window.physicalSize.width);
// initialize time zone current device
SharedPrefs().timeZone = getCurrentTimeZone(DateTime.now());
// url MP4 // url MP4
SharedPrefs().urlMP4 = SharedPrefs().urlMP4 =
'https://mp4.ikksgroup.com/MobilePortal4/index.html#ajax/dashboard.html'; 'https://mp4.ikksgroup.com/MobilePortal4/index.html#ajax/dashboard.html';

View File

@ -175,4 +175,11 @@ class SharedPrefs {
set photoSound(bool value) { set photoSound(bool value) {
_sharedPrefs.setBool('key_photo_sound', value); _sharedPrefs.setBool('key_photo_sound', value);
} }
/// get/set user time zone
String get timeZone => _sharedPrefs.getString('key_timeZone') ?? "";
set timeZone(String value) {
_sharedPrefs.setString('key_timeZone', value);
}
} }