getTimezoneInfoFromTimezoneId static method

ProgressListener? getTimezoneInfoFromTimezoneId({
  1. required String timezoneId,
  2. required DateTime time,
  3. void onComplete(
    1. GemError error,
    2. TimezoneResult? result
    )?,
})

Asynchronously retrieves timezone information for an IANA timezone id and an UTC timestamp.

Parameters

  • timezoneId: IANA timezone identifier in the form Continent/City (examples: Europe/Paris, America/New_York).
  • time: Instant to resolve (must be provided as a UTC DateTime).
  • onComplete: Function called when the operation completes. The function is called with:

Returns

Example

TimezoneService.getTimezoneInfoFromTimezoneId(
  timezoneId: 'Europe/Moscow',
  time: DateTime.utc(2025, 7, 1, 6, 0),
  onComplete: (err, result) {
    if (err == GemError.success) {
      print(result!.timezoneId);
    } else {
      print('Error: $err');
    }
  },
);

See also:

Implementation

static ProgressListener? getTimezoneInfoFromTimezoneId({
  required final String timezoneId,
  required final DateTime time,
  final void Function(GemError error, TimezoneResult? result)? onComplete,
}) {
  final TimezoneResult result = TimezoneResult.create();
  final EventDrivenProgressListener listener = EventDrivenProgressListener();
  GemKitPlatform.instance.registerEventHandler(listener.id, listener);

  listener.registerOnCompleteWithData((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(listener.id);
    if (err == 0) {
      onComplete?.call(GemErrorExtension.fromCode(err), result);
    } else {
      onComplete?.call(GemErrorExtension.fromCode(err), null);
    }
  });
  final OperationResult resultString = staticMethod(
    'TimezoneService',
    'getTimezoneInfoTimezoneId',
    args: <String, dynamic>{
      'timezoneResult': result.pointerId,
      'timezoneId': timezoneId,
      'time': time.millisecondsSinceEpoch,
      'progressListener': listener.id,
    },
  );
  final GemError errCode = GemErrorExtension.fromCode(resultString['result']);
  if (errCode != GemError.success) {
    onComplete?.call(errCode, null);
    return null;
  }
  return listener;
}