getSunriseAndSunset static method

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

Returns the sunrise and sunset times (UTC) for the supplied position and reference date.

The returned times are in UTC. Near the poles the sunrise or sunset may fall on a different calendar day; callers should treat these values as UTC instants.

Parameters

  • coords: (Coordinates) WGS84 coordinates for the location.
  • time: (DateTime) Reference date/time (used to compute seasonal sunrise/sunset times).

Returns

  • (DateTime, DateTime) Tuple where the first element is sunrise (UTC) and the second is sunset (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),
  );
}