getTimezoneInfoFromTimezoneId static method

ProgressListener? getTimezoneInfoFromTimezoneId({
  1. required String timezoneId,
  2. required DateTime time,
  3. bool accurateResult = false,
  4. required void onCompleteCallback(
    1. GemError error,
    2. TimezoneResult? result
    ),
})

Async gets timezone info based on a timezone if and a timestamp

Parameters

  • IN coords The location from where to get the timezone result
  • IN timezoneId The geographic location on earth of type: "Continent/City". Examples: Europe/Paris, America/New_York, Europe/Moscow
  • IN accurateResult If left 'false' the result will be computed using the available offline resource. If 'true' an HTTP request will be performed for computing the result
  • IN onCompleteCallback The callback which will be called when the operation completes.
    • Will be called with GemError.success error and non-null result upon success.
    • Will be called with GemError.internalAbort error and null result if the result parsing failed or server internal error occurred

Returns

  • ProgressListener for the operation progress if the operation could be started, null otherwise

Throws

  • An exception if it fails.

Implementation

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

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