initial commit

This commit is contained in:
2026-06-25 12:19:29 +03:00
commit 1160477945
19 changed files with 898 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
using RTCSync.Utils;
namespace RTCSync.Models;
public class TimeModel(ReadOnlySpan<byte> rtcBytes)
{
private static int CalculateHours(ReadOnlySpan<byte> rtcBytes)
{
var hours = 0;
if (TimeModelBI.TwentyHourBI.Take(rtcBytes) == 1)
{
hours = 20;
}
else if (TimeModelBI.TenHourBI.Take(rtcBytes) == 1)
{
hours = 10;
}
hours += TimeModelBI.HourBI.Take(rtcBytes);
return hours;
}
public DateTime Time = new DateTime(
2000 + TimeModelBI.TenYearBI.Take(rtcBytes) * 10 + TimeModelBI.YearBI.Take(rtcBytes),
TimeModelBI.TenMonthBI.Take(rtcBytes) * 10 + TimeModelBI.MonthBI.Take(rtcBytes),
TimeModelBI.TenDateBI.Take(rtcBytes) * 10 + TimeModelBI.DateBI.Take(rtcBytes),
CalculateHours(rtcBytes),
TimeModelBI.TenMinutesBI.Take(rtcBytes) * 10 + TimeModelBI.MinutesBI.Take(rtcBytes),
TimeModelBI.TenSecondsBI.Take(rtcBytes) * 10 + TimeModelBI.SecondsBI.Take(rtcBytes),
DateTimeKind.Local
);
}
+54
View File
@@ -0,0 +1,54 @@
using RTCSync.Utils;
namespace RTCSync.Models;
public class TimeModelBI
{
// 6 5 4 | 3 2 1 0
// 10 Seconds | Seconds
// 00 - 59
public static BitIndex[] SecondsBI { get; } = [new(1, 0..3)];
public static BitIndex[] TenSecondsBI { get; } = [new(1, 4..6)];
// 6 5 4 | 3 2 1 0
// 10 Minutes | Minutes
// 00 - 59
public static BitIndex[] MinutesBI { get; } = [new(2, 0..3)];
public static BitIndex[] TenMinutesBI { get; } = [new(2, 4..6)];
// 6 | 5 | 4 | 3 2 1 0
// 12/24 | 20 hour | 10 hour | Hour
// 1-12 + AM/PM
// 00 - 23
public static BitIndex[] HourBI { get; } = [new(3, 0..3)];
public static BitIndex[] TenHourBI { get; } = [new(3, 4..4)];
public static BitIndex[] TwentyHourBI { get; } = [new(3, 5..5)];
// When high - 12 hour format is selected
public static BitIndex[] HoursFormatBI { get; } = [new(3, 6..6)];
// 2 1 0
// Day
// 1 - 7
// 1 = Saturday, 2 = Monday
public static BitIndex[] DayOfWeekBI { get; } = [new(4, 0..3)];
// 5 4 | 3 2 1 0
// 10 Date | Date
// 01 - 31
public static BitIndex[] DateBI { get; } = [new(5, 0..4)];
public static BitIndex[] TenDateBI { get; } = [new(5, 4..5)];
// 7 | 4 | 3 2 1 0
// Century | 10 Month | Month
// 01 - 12 + Century
public static BitIndex[] MonthBI { get; } = [new(6, 0..3)];
public static BitIndex[] TenMonthBI { get; } = [new(6, 4..4)];
// High when the years register overflows from 99 to 00
public static BitIndex[] CenturyBI { get; } = [new(6, 7..7)];
// 7 6 5 4 | 3 2 1 0
// 10 Year | Year
// 0-99
public static BitIndex[] YearBI { get; } = [new(7, 0..3)];
public static BitIndex[] TenYearBI { get; } = [new(7, 4..7)];
}