Files
Aaru/Aaru.Filesystems/ISO9660/Date.cs

89 lines
3.7 KiB
C#
Raw Normal View History

2019-07-31 20:10:27 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2019-07-31 20:10:27 +01:00
// ----------------------------------------------------------------------------
//
// Filename : Date.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : ISO9660 filesystem plugin.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// In the loving memory of Facunda "Tata" Suárez Domínguez, R.I.P. 2019/07/24
2019-07-31 20:10:27 +01:00
// ****************************************************************************/
using System;
2020-02-27 00:33:26 +00:00
using Aaru.Helpers;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
public sealed partial class ISO9660
{
2022-11-13 19:59:24 +00:00
static DateTime? DecodeIsoDateTime(byte[] timestamp) => timestamp?.Length switch
{
2024-05-01 04:05:22 +01:00
7 => DecodeIsoDateTime(Marshal
.ByteArrayToStructureLittleEndian<
IsoTimestamp>(timestamp)),
17 => DateHandlers.Iso9660ToDateTime(timestamp),
_ => null
};
2019-07-28 18:32:15 +01:00
2022-03-06 13:29:38 +00:00
static DateTime? DecodeIsoDateTime(IsoTimestamp timestamp)
{
try
{
2024-05-01 04:05:22 +01:00
var date = new DateTime(timestamp.Years + 1900,
timestamp.Month,
timestamp.Day,
timestamp.Hour,
timestamp.Minute,
timestamp.Second,
DateTimeKind.Unspecified);
2022-03-06 13:29:38 +00:00
date = date.AddMinutes(timestamp.GmtOffset * 15);
2022-03-06 13:29:38 +00:00
return TimeZoneInfo.ConvertTimeToUtc(date, TimeZoneInfo.FindSystemTimeZoneById("GMT"));
}
catch(Exception)
{
// ISO says timestamp can be unspecified
return null;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
static DateTime? DecodeHighSierraDateTime(HighSierraTimestamp timestamp)
{
try
{
2024-05-01 04:05:22 +01:00
var date = new DateTime(timestamp.Years + 1900,
timestamp.Month,
timestamp.Day,
timestamp.Hour,
timestamp.Minute,
timestamp.Second,
DateTimeKind.Unspecified);
2022-03-06 13:29:38 +00:00
return TimeZoneInfo.ConvertTimeToUtc(date, TimeZoneInfo.FindSystemTimeZoneById("GMT"));
}
catch(Exception)
{
// ISO says timestamp can be unspecified, suppose same for High Sierra
return null;
}
}
}