Skip to content

Commit

Permalink
convert Source.Date string to DateOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
rsek committed Jan 5, 2022
1 parent 1491258 commit b4982d8
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions TheOracle2/DataClassesNext/Source.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit b4982d8

Please sign in to comment.