F # Units ... Is there an TIME example?

Is TIME used in F # units?

+3
source share
2 answers

there is a standard SI unit β€œsecond” that you can use to represent time. You will need to specify the FSharp.PowerPack.dll file, and then you can use the following:

open Microsoft.FSharp.Math

let minute = 60<SI.s>
let twoMinutes = minute * 2

There are no built-in units in minutes / hours, etc., since they are not standard units (and in fact only seconds are multiplied by a certain amount). However, you can also determine the minutes if you want:

[<Measure>]
type mins =
  static member of_seconds(sec) = sec / 60<SI.s> * 1<mins>

// converting seconds to minutes 
let timeInMinuts = mins.of_seconds(twoMinutes)

System.DateTime, , , (/) , :

open System

type DateTimeUnits(dt:DateTime) = 
  static member Now = new DateTimeUnits(DateTime.Now)
  member x.Second = dt.Second * 1<SI.s>
  member x.Minute = dt.Minute * 1<mins>
+10

Source: https://habr.com/ru/post/1716258/


All Articles