mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-22 20:13:06 +00:00
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
This commit is contained in:
parent
7122c5c3f5
commit
8a29320724
3 changed files with 9 additions and 8 deletions
|
@ -11,8 +11,8 @@ public sealed class Epoch0000DateTime(Memory<byte> 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 sealed class Epoch0000DateTime(Memory<byte> Data): EpochDateTime(Data)
|
|||
}
|
||||
}
|
||||
|
||||
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 :
|
||||
|
||||
/// <summary>
|
||||
/// time_t
|
||||
|
|
|
@ -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<byte> 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;
|
||||
|
|
|
@ -7,8 +7,10 @@ public abstract class EpochDateTime(Memory<byte> Data)
|
|||
{
|
||||
protected Span<byte> 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); }
|
||||
|
|
Loading…
Reference in a new issue