Files

21 lines
789 B
Dart
Raw Permalink Normal View History

// The device's IANA time zone, which the statistics API wants for bucketing
// days. Dart only exposes the abbreviation ("CST"), and Guava/ICU's zone id
// lives on the Android side; the desktop build has no zone plugin, so it
// falls back to UTC (the UI still works, only the day boundaries shift).
import 'package:flutter/services.dart';
const _channel = MethodChannel('openchamber/device');
String? _cached;
Future<String> deviceTimeZone() async {
final cached = _cached;
if (cached != null) return cached;
try {
final name = await _channel.invokeMethod<String>('ianaTimeZone');
if (name != null && name.isNotEmpty) return _cached = name;
} catch (_) {
// No handler (desktop) or a platform failure: UTC keeps the request valid.
}
return _cached = 'UTC';
}