getTimezoneInfoFromTimezoneId static method
ProgressListener?
getTimezoneInfoFromTimezoneId({
- required String timezoneId,
- required DateTime time,
- void onComplete(
- GemError error,
- TimezoneResult? result
Asynchronously retrieves timezone information for an IANA timezone id and an UTC timestamp.
Parameters
timezoneId: IANA timezone identifier in the formContinent/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:- GemError.success for
errorand a non-null TimezoneResult forresultwhen the operation completed successfully. - GemError.internalAbort for
errorandnullforresultwhen a parsing failure or server-side error occurred.
- GemError.success for
Returns
- A ProgressListener if the asynchronous operation was started;
nullif the operation could not be started. Whennullthe specific failure can be inspected via ApiErrorService.apiError.
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:
- TimezoneResult - The result object that exposes the status and offsets.
- getTimezoneInfoTimezoneIdSync - Synchronous version of this method.
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;
}