From b4982d8219efc416d8ae21657d791309380e35b2 Mon Sep 17 00:00:00 2001 From: rsek Date: Tue, 4 Jan 2022 18:17:11 -0800 Subject: [PATCH] convert Source.Date string to DateOnly --- TheOracle2/DataClassesNext/Source.cs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/TheOracle2/DataClassesNext/Source.cs b/TheOracle2/DataClassesNext/Source.cs index 9b8bce7..fce7da3 100644 --- a/TheOracle2/DataClassesNext/Source.cs +++ b/TheOracle2/DataClassesNext/Source.cs @@ -1,6 +1,27 @@ namespace TheOracle2.DataClassesNext; -public class SourceData { +public class Source +{ public string Name { get; set; } - public string Date { get; set; } - public int Page { get; set; } + public int? Page { get; set; } + [JsonProperty("Date")] + private string RawDate { get; set; } + [JsonIgnore] + public DateOnly Date + // TODO: rewrite as a proper converter. it's arguable whether the Dataforged date string (e.g. "122421") needs to be a Date anyways... but maybe it'll have some use in managing user DB content? + { + get + { + int month = Int16.Parse(RawDate.Substring(0, 2)); + int day = Int16.Parse(RawDate.Substring(2, 2)); + int year = Int16.Parse(RawDate.Substring(4, 2)) + 2000; + return new DateOnly(year, month, day); + } + } + public override string ToString() + { + var outputStr = Name; + if (RawDate != null) { outputStr = outputStr + $" {Date.ToString("MMddyy")}"; } + if (Page != 0) { outputStr = outputStr + $", p. {Page}"; } + return outputStr; + } }