From 37fe5f00d05110ba47c0664945dc01f4c6e99846 Mon Sep 17 00:00:00 2001 From: hadashiA Date: Fri, 22 Sep 2023 17:39:03 +0900 Subject: [PATCH] Fix the bits of Time in big-endian case --- src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs | 8 ++++---- src/Ulid/Ulid.cs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs b/src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs index d034534..0e6b351 100644 --- a/src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs +++ b/src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs @@ -93,7 +93,7 @@ public DateTimeOffset Time { if (BitConverter.IsLittleEndian) { - // |A|B|C|D|E|F|G|H|... -> |F|E|D|C|B|A|0|0| + // |A|B|C|D|E|F|... -> |F|E|D|C|B|A|0|0| // Lower |A|B|C|D| -> |D|C|B|A| // Upper |E|F| -> |F|E| @@ -105,14 +105,14 @@ public DateTimeOffset Time } else { - // |A|B|C|D|E|F|G|H|... -> |A|B|C|D|E|F|0|0| + // |A|B|C|D|E|F|... -> |0|0|A|B|C|D|E|F| // Upper |A|B|C|D| // Lower |E|F| - // Time |A|B|C|D| + |E|F|0|0| + // Time |A|B|C|C|0|0| + |E|F| var upper = Unsafe.As(ref Unsafe.AsRef(this.timestamp0)); var lower = Unsafe.As(ref Unsafe.AsRef(this.timestamp4)); - var time = ((long)upper << 32) + ((long)lower << 16); + var time = ((long)upper << 16) + (long)lower; return DateTimeOffset.FromUnixTimeMilliseconds(time); } } diff --git a/src/Ulid/Ulid.cs b/src/Ulid/Ulid.cs index d034534..0e6b351 100644 --- a/src/Ulid/Ulid.cs +++ b/src/Ulid/Ulid.cs @@ -93,7 +93,7 @@ public DateTimeOffset Time { if (BitConverter.IsLittleEndian) { - // |A|B|C|D|E|F|G|H|... -> |F|E|D|C|B|A|0|0| + // |A|B|C|D|E|F|... -> |F|E|D|C|B|A|0|0| // Lower |A|B|C|D| -> |D|C|B|A| // Upper |E|F| -> |F|E| @@ -105,14 +105,14 @@ public DateTimeOffset Time } else { - // |A|B|C|D|E|F|G|H|... -> |A|B|C|D|E|F|0|0| + // |A|B|C|D|E|F|... -> |0|0|A|B|C|D|E|F| // Upper |A|B|C|D| // Lower |E|F| - // Time |A|B|C|D| + |E|F|0|0| + // Time |A|B|C|C|0|0| + |E|F| var upper = Unsafe.As(ref Unsafe.AsRef(this.timestamp0)); var lower = Unsafe.As(ref Unsafe.AsRef(this.timestamp4)); - var time = ((long)upper << 32) + ((long)lower << 16); + var time = ((long)upper << 16) + (long)lower; return DateTimeOffset.FromUnixTimeMilliseconds(time); } }