From 8a29320724b2c3954674399bc95da618b23fd685 Mon Sep 17 00:00:00 2001 From: Jonathan Herbert Date: Mon, 11 Mar 2024 16:07:59 -0400 Subject: [PATCH] Minor Changes To EpochDateTime (#4214) - Fix Epoch0000DateTime.DisplayValue having seconds in the output even though they aren't stored - Introduce RawYear and RawMonth in EpochDateTime to reduce duplicated logic --- PKHeX.Core/Saves/Substructures/Time/Epoch0000DateTime.cs | 6 +++--- .../Saves/Substructures/Time/Epoch1900DateTimeValue.cs | 5 ++--- PKHeX.Core/Saves/Substructures/Time/EpochDateTime.cs | 6 ++++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/PKHeX.Core/Saves/Substructures/Time/Epoch0000DateTime.cs b/PKHeX.Core/Saves/Substructures/Time/Epoch0000DateTime.cs index 4c4e64fd6..cb959fde1 100644 --- a/PKHeX.Core/Saves/Substructures/Time/Epoch0000DateTime.cs +++ b/PKHeX.Core/Saves/Substructures/Time/Epoch0000DateTime.cs @@ -11,8 +11,8 @@ public sealed class Epoch0000DateTime(Memory Data): EpochDateTime(Data) private static DateTime Epoch => new(0, 1, 1); - public override int Year { get => (int)(RawDate & 0xFFF); set => RawDate = (RawDate & 0xFFFFF000) | (uint)(value); } - public override int Month { get => (int)((RawDate >> 12) & 0xF); set => RawDate = (RawDate & 0xFFFF0FFF) | (((uint)value & 0xF) << 12); } + public override int Year { get => RawYear; set => RawYear = value; } + public override int Month { get => RawMonth; set => RawMonth = value; } public override DateTime Timestamp { @@ -27,7 +27,7 @@ public override DateTime Timestamp } } - public override string DisplayValue => $"{Timestamp.Year:0000}-{Timestamp.Month:00}-{Timestamp.Day:00} {Timestamp.Hour:00}ː{Timestamp.Minute:00}ː{Timestamp.Second:00}"; // not : + public override string DisplayValue => $"{Timestamp.Year:0000}-{Timestamp.Month:00}-{Timestamp.Day:00} {Timestamp.Hour:00}ː{Timestamp.Minute:00}"; // not : /// /// time_t diff --git a/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs b/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs index 993ff0f1f..c8077062f 100644 --- a/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs +++ b/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel; -using static System.Buffers.Binary.BinaryPrimitives; namespace PKHeX.Core; @@ -17,8 +16,8 @@ public sealed class Epoch1900DateTimeValue(Memory Data) : EpochDateTime(Da private static DateTime Epoch => new(1900, 1, 1); - public override int Year { get => (int)(RawDate & 0xFFF) + Epoch.Year; set => RawDate = (RawDate & 0xFFFFF000) | (uint)(value - Epoch.Year); } - public override int Month { get => (int)((RawDate >> 12) & 0xF) + 1; set => RawDate = (RawDate & 0xFFFF0FFF) | (((uint)(value - 1) & 0xF) << 12); } + public override int Year { get => RawYear + Epoch.Year; set => RawYear = value - Epoch.Year; } + public override int Month { get => RawMonth + 1; set => RawMonth = value - 1; } public bool HasSeconds => Span.Length > 4; public int Second { get => HasSeconds ? Span[4] : 0; diff --git a/PKHeX.Core/Saves/Substructures/Time/EpochDateTime.cs b/PKHeX.Core/Saves/Substructures/Time/EpochDateTime.cs index 4037bff26..85f4f46ea 100644 --- a/PKHeX.Core/Saves/Substructures/Time/EpochDateTime.cs +++ b/PKHeX.Core/Saves/Substructures/Time/EpochDateTime.cs @@ -7,8 +7,10 @@ public abstract class EpochDateTime(Memory Data) { protected Span Span => Data.Span; protected uint RawDate { get => ReadUInt32LittleEndian(Span); set => WriteUInt32LittleEndian(Span, value); } - public abstract int Year { get; set;} - public abstract int Month { get; set;} + protected int RawYear { get => (int)(RawDate & 0xFFF); set => RawDate = (RawDate & 0xFFFFF000) | (uint)(value); } + public abstract int Year { get; set; } + protected int RawMonth { get => (int)((RawDate >> 12) & 0xF); set => RawDate = (RawDate & 0xFFFF0FFF) | (((uint)value & 0xF) << 12); } + public abstract int Month { get; set; } public int Day { get => (int)((RawDate >> 16) & 0x1F); set => RawDate = (RawDate & 0xFFE0FFFF) | (((uint)value & 0x1F) << 16); } public int Hour { get => (int)((RawDate >> 21) & 0x1F); set => RawDate = (RawDate & 0xFC1FFFFF) | (((uint)value & 0x1F) << 21); } public int Minute { get => (int)((RawDate >> 26) & 0x3F); set => RawDate = (RawDate & 0x03FFFFFF) | (((uint)value & 0x3F) << 26); }