PKHeX/PKHeX.Core/Saves/Substructures/Time/Epoch1970Value.cs
Jonathan Herbert 92c964d6fa
Refactor And Deduplicate Some Switch Games Common Logic (#4187)
- 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.
2024-02-23 13:19:17 -06:00

35 lines
1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 1970 that an event occurred.
/// </summary>
[TypeConverter(typeof(ExpandableObjectConverter))]
public sealed class Epoch1970Value(Memory<byte> Data)
{
private Span<byte> Span => Data.Span;
public Epoch1970Value(SCBlock block) : this(block.Data) { }
/// <summary>
/// time_t (seconds since 1970 Epoch)
/// </summary>
public ulong Seconds
{
get => ReadUInt64LittleEndian(Span);
set => WriteUInt64LittleEndian(Span, value);
}
private static DateTime Epoch => new(1970, 1, 1);
public string DisplayValue => $"{Timestamp.Year:0000}-{Timestamp.Month:00}-{Timestamp.Day:00} {Timestamp.Hour:00}ː{Timestamp.Minute:00}ː{Timestamp.Second:00}"; // not :
public DateTime Timestamp
{
get => Epoch.AddSeconds(Seconds);
set => Seconds = (ulong)value.Subtract(Epoch).TotalSeconds;
}
}