PKHeX/PKHeX.Core/Saves/Substructures/Gen8/LA/AdventureStart8a.cs
Kurt 691f941bb6 Add savedata models
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>
Co-Authored-By: SciresM <8676005+SciresM@users.noreply.github.com>
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
2022-02-04 17:31:20 -08:00

34 lines
1.0 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.Buffers.Binary;
using System.ComponentModel;
namespace PKHeX.Core;
/// <summary>
/// Stores the <see cref="Timestamp"/> when the player created their save data.
/// </summary>
[TypeConverter(typeof(ExpandableObjectConverter))]
public sealed class AdventureStart8a : SaveBlock
{
public AdventureStart8a(SaveFile sav, SCBlock block) : base(sav, block.Data) { }
/// <summary>
/// time_t (seconds since 1970 Epoch)
/// </summary>
public ulong Seconds
{
get => BinaryPrimitives.ReadUInt64LittleEndian(Data.AsSpan(Offset));
set => BinaryPrimitives.WriteUInt64LittleEndian(Data.AsSpan(Offset), value);
}
private static DateTime Epoch => new(1970, 1, 1);
public string AdventureStartTime => $"{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;
}
}