| | | 1 | | using Anichron.Core.Domain; |
| | | 2 | | using GeoTimeZone; |
| | | 3 | | using NodaTime; |
| | | 4 | | |
| | | 5 | | namespace Anichron.Worker.Ingestion.Extraction; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// The time zones a capture date is read in: the zone at a position, looked up offline (GeoTimeZone's boundary data, |
| | | 9 | | /// then NodaTime's tzdb), else the library's zone. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="zones">The zones the lookup's ids resolve in.</param> |
| | | 12 | | /// <param name="library">The library's zone, the host's system zone.</param> |
| | | 13 | | /// <param name="logger">Logs an id the zones do not know.</param> |
| | 82 | 14 | | internal sealed partial class CaptureZones(IDateTimeZoneProvider zones, DateTimeZone library, ILogger<CaptureZones> logg |
| | | 15 | | { |
| | | 16 | | /// <summary>The capture date of what extraction read, null when it is undated; an undated asset is never looked up. |
| | | 17 | | /// <param name="extracted">What extraction read from the file.</param> |
| | 61 | 18 | | public CaptureDate? DateOf(ExtractedMedia extracted) => extracted.Recorded?.In(At(extracted.Description), library); |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// The zone at the described position; null without a position on the globe, or when NodaTime does not know the |
| | | 22 | | /// zone found. The lookup answers even for coordinates off the globe, so those count as no position. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="description">The asset's description, holding its position.</param> |
| | | 25 | | public DateTimeZone? At(MediaDescription description) |
| | 72 | 26 | | { |
| | 72 | 27 | | if (description is not { Latitude: >= -90 and <= 90 and var latitude, Longitude: >= -180 and <= 180 and var long |
| | 41 | 28 | | return null; |
| | | 29 | | |
| | 31 | 30 | | var id = TimeZoneLookup.GetTimeZone(latitude, longitude).Result; |
| | 31 | 31 | | var zone = zones.GetZoneOrNull(id); |
| | 31 | 32 | | if (zone is null) |
| | 1 | 33 | | Log.UnknownZone(logger, id, latitude, longitude); |
| | 31 | 34 | | return zone; |
| | 72 | 35 | | } |
| | | 36 | | |
| | | 37 | | private static partial class Log |
| | | 38 | | { |
| | | 39 | | [LoggerMessage(Level = LogLevel.Debug, Message = "No time zone for {Latitude}, {Longitude}: NodaTime does not kn |
| | | 40 | | public static partial void UnknownZone(ILogger logger, string zoneId, double latitude, double longitude); |
| | | 41 | | } |
| | | 42 | | } |