// //------------------ DOK FILE -------------------------------------------------- +Header timeLib =pkg bios =title Time =short time, date, timeout, sleep, ... =desc // // //------------------ PROTO ----------------------------------------------------- T0 +Proto T0 =type Int =mode constant =pkg bios =impl mcy =link =desc This constant is the timestamp at the start of the Minimacy VM. // // //------------------ PROTO ----------------------------------------------------- timeMs +Proto timeMs =type fun -> Int =mode function =pkg bios =impl native =link =desc This function returns the current time as a number of milliseconds since 01/01/1970. // +arg result =type Int =desc An integer // // //------------------ PROTO ----------------------------------------------------- yyddmmhhmmsszFromTime +Proto yyddmmhhmmsszFromTime =type fun Int -> Str =mode function =pkg bios =impl mcy =link =desc This function returns the date in the format YYDDMMHHMMSSZ. > yyddmmhhmmsszFromTime (time()) >-> Str: "220510205131Z" // +arg t =type Int =desc A timestamp in seconds, typically the value of the [[time]] function // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- timeFromYyddmmhhmmssz +Proto timeFromYyddmmhhmmssz =type fun Str -> Int =mode function =pkg bios =impl mcy =link =desc This function computes a timestamp from a date in the format YYDDMMHHMMSSZ. > timeFromYyddmmhhmmssz ("220510205131Z") >-> Int: 1652215891 (0x627AD053) // +arg src =type Str =desc A string date in the format YYDDMMHHMMSSZ // +arg result =type Int =desc A timestamp in seconds // // //------------------ PROTO ----------------------------------------------------- date +Proto date =type fun Int -> [Int Int Int Int Int Int Int] =mode function =pkg bios =impl mcy =link =desc This function computes the UTC date from a timestamp. - year: the full year, for example 2022 - month: january is 1, december is 12 - day: 1 is the 1st day of the month - weekDay: sunday is 0, saturday is 6 > date (time()) >-> [Int Int Int Int Int Int Int]: #7 [ > 0: > Int: 2022 (0x7E6) > 1: > Int: 5 (0x5) > 2: > Int: 10 (0xA) > 3: > Int: 2 (0x2) > 4: > Int: 21 (0x15) > 5: > Int: 0 (0x0) > 6: > Int: 41 (0x29) >] // +arg t =type Int =desc A timestamp in seconds // +arg result =type [Int Int Int Int Int Int Int] =desc A tuple [year month day weekDay hour minute second] // // //------------------ PROTO ----------------------------------------------------- smallTime +Proto smallTime =type fun Int -> Str =mode Function =pkg bios =impl mcy =link =desc > smallTime (time()) >-> Str: "21:04:43" // +arg t =type Int =desc // +arg result =type Str =desc // // //------------------ PROTO ----------------------------------------------------- fullDate +Proto fullDate =type fun Int -> Str =mode function =pkg bios =impl mcy =link =desc > fullDate (time()) >-> Str: "Tue, 10 May 2022 21:04:43 UTC" // +arg t =type Int =desc A timestamp in seconds // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- fileDate +Proto fileDate =type fun Int -> Str =mode function =pkg bios =impl mcy =link =desc > fileDate (time()) >-> Str: "05/10/2022 21:04" // +arg t =type Int =desc A timestamp in seconds // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- fileDateSeconds +Proto fileDateSeconds =type fun Int -> Str =mode function =pkg bios =impl mcy =link =desc > fileDateSeconds (time()) >-> Str: "05/10/2022 21:04:57" // +arg t =type Int =desc A timestamp in seconds // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- onTimeout +Proto onTimeout =type fun Int (fun -> a1) -> Bool =mode function =pkg bios =impl mcy =link =desc This function defines a lambda function which will be called once, on the same thread, after at least duration milliseconds. // +arg duration =type Int =desc A duration in milliseconds // +arg fTimeout =type fun -> a1 =desc A lambda function with no argument and any result // +arg result =type Bool =desc Always true // // //------------------ PROTO ----------------------------------------------------- sleepMs +Proto sleepMs =type fun Int -> Bool =mode function =pkg bios =impl mcy =link =desc This function freezes for a give number of milliseconds. The other threads are still running. // +arg ms =type Int =desc A positive integer // +arg result =type Bool =desc Always true // // //------------------ PROTO ----------------------------------------------------- smallDate +Proto smallDate =type fun Int -> Str =mode function =pkg bios =impl mcy =link =desc > smallDate (time()) >-> Str: "16:30:28" > smallDate (time()-3600*16) >-> Str: "00:30:38" > smallDate (time()-3600*24) >-> Str: "05/22" // +arg t =type Int =desc A timestamp in seconds // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- time +Proto time =type fun -> Int =mode function =pkg bios =impl native =link explicit =desc This function returns the current time as a number of seconds since 01/01/1970. // +arg result =type Int =desc An integer // // //------------------ PROTO ----------------------------------------------------- timeFromDate +Proto timeFromDate =type fun Int Int Int Int Int Int -> Int =mode function =pkg bios =impl mcy =link =desc This function computes a timestamp from a UTC date defined by year, month, day, hour, minute, second. > timeFromDate (2022, 5, 10, 21, 09, 47) >-> Int: 1652216447 (0x627AD27F) // +arg year =type Int =desc An integer such as 2022 and greater than 1970 // +arg month =type Int =desc january is 1, december is 12 // +arg day =type Int =desc 1 is the 1st day in the month // +arg h =type Int =desc // +arg m =type Int =desc // +arg s =type Int =desc // +arg result =type Int =desc A timestamp // // //------------------ PROTO ----------------------------------------------------- Months +Proto Months =type array Str =mode constant =pkg bios =impl mcy =link =desc An array of month names (3 letters, english). > Months[0] >-> Str: "Jan" > Months[11] >-> Str: "Dec" // // //------------------ PROTO ----------------------------------------------------- Days +Proto Days =type array Str =mode constant =pkg bios =impl mcy =link =desc An array of day names (3 letters, english). > Days[0] >-> Str: "Sun" > Days[6] >-> Str: "Sat"