mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-12 13:42:36 +00:00
92c964d6fa
- Improve Epoch 1900 classes using similar logic from PlayTime7b. - Move Time Classes into non Gen specific folder since it appears the logic is shared across a few of them. - Use Epoch1900DateTimeValue for LastSaved in PlayTime7b since the logic is the same. - Remove TeamIndexes9 since it is a duplicate of TeamIndexes9. Use the similar pattern like Box8 where it is reused in multiple locations. - Add BlueberryClubRoom9 to ISaveBlock9Main since it wasn't added when the class was introduced. - Simplify RaidSevenStar9 creation since GetBlockSafe does basically what the if-else block does. - Change SAV8SWSH Base Raid to RaidGalar to match the same way the SAV9SV does for its Base Raid.
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using System;
|
||
using System.ComponentModel;
|
||
using static System.Buffers.Binary.BinaryPrimitives;
|
||
|
||
namespace PKHeX.Core;
|
||
|
||
/// <summary>
|
||
/// Stores the <see cref="Timestamp"/> to indicate the seconds since 1900 (rounded to days) that an event occurred.
|
||
/// </summary>
|
||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||
public sealed class Epoch1900DateValue(Memory<byte> Data)
|
||
{
|
||
// Data should be 4 bytes where we only care about the first 3 bytes i.e. 24 bits
|
||
// First 12 bits are year from 1900, next 6 bits are 0 indexed month, next 6 are days
|
||
private Span<byte> Span => Data.Span;
|
||
|
||
public Epoch1900DateValue(SCBlock block) : this(block.Data) { }
|
||
|
||
private static DateTime Epoch => new(1900, 1, 1);
|
||
|
||
private uint RawDate { get => ReadUInt32LittleEndian(Span); set => WriteUInt32LittleEndian(Span, value); }
|
||
public int Year { get => (int)(RawDate & 0xFFF) + Epoch.Year; set => RawDate = (RawDate & 0xFFFFF000) | (uint)(value - Epoch.Year); }
|
||
public int Month { get => (int)((RawDate >> 12) & 0x3F) + 1; set => RawDate = (RawDate & 0xFFFC0FFF) | (((uint)(value - 1) & 0x3F) << 12); }
|
||
public int Day { get => (int)((RawDate >> 18) & 0x3F); set => RawDate = (RawDate & 0xFF03FFFF) | (((uint)value & 0x3F) << 18); }
|
||
|
||
public DateTime Timestamp
|
||
{
|
||
get => new(Year, Month, Day);
|
||
set
|
||
{
|
||
Year = value.Year;
|
||
Month = value.Month;
|
||
Day = value.Day;
|
||
}
|
||
}
|
||
|
||
public string DisplayValue => $"{Timestamp.Year:0000}-{Timestamp.Month:00}-{Timestamp.Day:00} {Timestamp.Hour:00}ː{Timestamp.Minute:00}ː{Timestamp.Second:00}"; // not :
|
||
|
||
/// <summary>
|
||
/// time_t (seconds since 1900 Epoch rounded to days)
|
||
/// </summary>
|
||
public ulong TotalSeconds
|
||
{
|
||
get => (ulong)(Timestamp - Epoch).TotalSeconds;
|
||
set => Timestamp = Epoch.AddSeconds(value);
|
||
}
|
||
}
|