| | | 1 | | using Anichron.Core.Domain; |
| | | 2 | | using NodaTime; |
| | | 3 | | |
| | | 4 | | namespace Anichron.Worker.Ingestion.Extraction; |
| | | 5 | | |
| | | 6 | | /// <summary>A capture date as a file records it: a clock time, a date alone, or a moment recorded only in UTC.</summary |
| | | 7 | | internal abstract record RecordedDate |
| | | 8 | | { |
| | 198 | 9 | | private RecordedDate() |
| | 198 | 10 | | { |
| | 198 | 11 | | } |
| | | 12 | | |
| | | 13 | | /// <summary>The capture date, with the time zone at the asset's position; the zone never changes a recorded clock t |
| | | 14 | | /// <param name="atPosition">The zone at the asset's position, if it has one.</param> |
| | | 15 | | /// <param name="library">The library's zone, which reads a moment recorded without a position.</param> |
| | | 16 | | public abstract CaptureDate In(DateTimeZone? atPosition, DateTimeZone library); |
| | | 17 | | |
| | | 18 | | /// <summary>A clock time, with the offset the file records beside it.</summary> |
| | | 19 | | /// <param name="At">The recorded clock time.</param> |
| | | 20 | | /// <param name="Offset">The recorded offset, if any.</param> |
| | | 21 | | internal sealed record ClockTime(LocalDateTime At, Offset? Offset) : RecordedDate |
| | | 22 | | { |
| | | 23 | | public override CaptureDate In(DateTimeZone? atPosition, DateTimeZone library) |
| | 53 | 24 | | => new(At, Offset, CaptureSource.Recorded, atPosition?.Id); |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary>A date the file records without a time; it dates the asset at 00:00 and keeps no offset.</summary> |
| | | 28 | | /// <param name="Date">The recorded date.</param> |
| | | 29 | | internal sealed record DateAlone(LocalDate Date) : RecordedDate |
| | | 30 | | { |
| | | 31 | | public override CaptureDate In(DateTimeZone? atPosition, DateTimeZone library) |
| | 3 | 32 | | => new(Date.AtMidnight(), null, CaptureSource.RecordedDateOnly, atPosition?.Id); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary>A moment the file records only in UTC; it keeps no offset, since the zone it is read in gives one.</sum |
| | | 36 | | /// <param name="At">The recorded moment.</param> |
| | | 37 | | internal sealed record Moment(Instant At) : RecordedDate |
| | | 38 | | { |
| | | 39 | | public override CaptureDate In(DateTimeZone? atPosition, DateTimeZone library) |
| | 4 | 40 | | => new(At.InZone(atPosition ?? library).LocalDateTime, null, CaptureSource.RecordedInUtc, atPosition?.Id); |
| | | 41 | | } |
| | | 42 | | } |