Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Protobuf.FSharp/BuiltinTypes/Timestamp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module TimestampReflection =
true
)
let Descriptor(): global.Google.Protobuf.Reflection.FileDescriptor = descriptorBackingField.Value
// Start of hand-written code
[<CustomComparison; CustomEquality>]
// End of hand-written code
type Timestamp = {
mutable _UnknownFields: global.Google.Protobuf.UnknownFieldSet
mutable Seconds: int64
Expand All @@ -56,6 +59,31 @@ type Timestamp = {
member me.ToDateTimeOffset() : ValueOption<System.DateTimeOffset> =
let ticks = int64 me.Nanos / 100L + me.Seconds * System.TimeSpan.TicksPerSecond
ValueSome(System.DateTimeOffset(Timestamp.unixEpoch.AddTicks(ticks)))

interface System.IEquatable<Timestamp> with
member this.Equals other = other.Seconds.Equals this.Seconds && other.Nanos.Equals this.Nanos

override this.Equals other =
match other with
| :? Timestamp as otherTimestamp -> (this :> System.IEquatable<_>).Equals otherTimestamp
| _ -> false

override this.GetHashCode() =
((System.Numerics.BigInteger(this.Seconds) <<< 32) + System.Numerics.BigInteger(this.Nanos)).GetHashCode()

interface System.IComparable<Timestamp> with
member this.CompareTo(other: Timestamp) =
if this.Seconds > other.Seconds then 1
else if this.Seconds < other.Seconds then -1
else if this.Nanos > other.Nanos then 1
else if this.Nanos < other.Nanos then -1
else 0

interface System.IComparable with
member this.CompareTo other =
match other with
| :? Timestamp as otherTimestamp -> (this :> System.IComparable<_>).CompareTo otherTimestamp
| _ -> -1
// End of hand-written code
[<global.System.Diagnostics.DebuggerNonUserCodeAttribute>]
member me.Clone() : Timestamp = {
Expand Down