I would like to extend DateTime in the following fashion:
[<AutoOpen>]
type System.DateTime with
member this.floor (interval: TimeSpan) =
this.AddTicks(-(this.Ticks % interval.Ticks))
member this.ceiling (interval: TimeSpan) =
let overflow = this.Ticks % interval.Ticks
if overflow = 0 then this else this.AddTicks(interval.Ticks - overflow)
member this.round (interval: TimeSpan) =
let halfIntervalTicks = (interval.Ticks + 1) >>> 1
this.AddTicks(halfIntervalTicks - ((this.Ticks + halfIntervalTicks) % interval.Ticks))
based on aj.toulan's C# answer at: DateTime Round Up and Down
but this won't work; apparently I should be using a module, but then how do I get the 'this' part? what would be the right syntax?
I get this error:
[FS0644] Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members.