getSunriseAndSunset static method

(DateTime, DateTime) getSunriseAndSunset(
  1. Coordinates coords,
  2. DateTime time
)

Get the sunrise & sunset for the specified reference date and WGS position.

The sunset may happen next day or even later (close to poles). Returned value is UTC. The sunrise may happen in the same day or before (close to poles). Returned value is UTC.

Parameters

Returns

  • A record with sunrise and sunset, first is sunrise, second is sunset, both as DateTime in UTC.

Implementation

static (DateTime, DateTime) getSunriseAndSunset(
  final Coordinates coords,
  final DateTime time,
) {
  final OperationResult resultString = staticMethod(
    'MapDetails',
    'getSunriseAndSunset',
    args: <String, Object>{
      'coords': coords,
      'refTime': time.millisecondsSinceEpoch,
    },
  );

  final Map<String, dynamic> result =
      resultString['result'] as Map<String, dynamic>;
  final int first = result['first'];
  final int second = result['second'];

  return (
    DateTime.fromMillisecondsSinceEpoch(first, isUtc: true),
    DateTime.fromMillisecondsSinceEpoch(second, isUtc: true),
  );
}