forked from XenotropicDev/TheOracle2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert Source.Date string to DateOnly
- Loading branch information
Showing
1 changed file
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |