diff --git a/lib/Time.ex.fm b/lib/Time.ex.fm new file mode 100644 index 00000000..984e7f6c --- /dev/null +++ b/lib/Time.ex.fm @@ -0,0 +1,46 @@ +Time.ex.parse: Time + Time.parse_ms(1337000001l) + +Time.ex.show_seconds: String + let time = Time.show(Time.ex.parse, Bool.false) + case time: + | time.seconds; + +// Time.ex.show_secs: The(_, Bool.true) +// let time = Time.show(Time.ex.parse, Bool.false) +// case time: +// | The.value<>(String.eql(time.seconds, "20s")); + +Time.ex.show_hours_min: String + let time = Time.show(Time.ex.parse, Bool.false) + case time: + | String.concat(time.minutes, String.concat(" ", time.seconds)); + +Time.ex.show: Time.stringify + Time.show(Time.ex.parse, Bool.false) + +// TODO: add proof that returns Bool.true +Time.ex.prettify_0: Bool + let parsed = Time.parse_ms(144000000l) + let res = Time.prettify(parsed, Bool.true) + String.eql(res, "1 day 16 hours ") + +Time.ex.prettify_1: Bool + let res = Time.prettify(Time.ex.parse, Bool.false) + String.eql(res, "15d 11h 23m 20s 1ms ") + +// TODO: add proof that returns Bool.true +Time.ex.test_days: Bool + let time = Time.ex.parse + case time: + | U64.eql(time.days, 15l); + +Time.ex.prettify: String + Time.prettify(Time.parse_ms(144000000l), Bool.true) + +// TODO: do not check. idk why... +// Time.ex: Bool +// Bool.and(Time.ex.test_days, Bool.false) + +// Time.ex.test: Time.ex.test_days == Bool.true +// _ diff --git a/lib/Time.fm b/lib/Time.fm new file mode 100644 index 00000000..7117cbe1 --- /dev/null +++ b/lib/Time.fm @@ -0,0 +1,9 @@ +T Time +| Time.new( + days: U64, + hours: U64, + minutes: U64, + seconds: U64, + milliseconds: U64, + microseconds: U64, + nanoseconds: U64); \ No newline at end of file diff --git a/lib/Time.parse_days.fm b/lib/Time.parse_days.fm new file mode 100644 index 00000000..3a7cc1f4 --- /dev/null +++ b/lib/Time.parse_days.fm @@ -0,0 +1,2 @@ +Time.parse_days(ms: U64): U64 + U64.div(ms, 86400000l) \ No newline at end of file diff --git a/lib/Time.parse_hours.fm b/lib/Time.parse_hours.fm new file mode 100644 index 00000000..3c6acd77 --- /dev/null +++ b/lib/Time.parse_hours.fm @@ -0,0 +1,2 @@ +Time.parse_hours(ms: U64): U64 + U64.mod(U64.div(ms, 3600000l), 24l) \ No newline at end of file diff --git a/lib/Time.parse_microseconds.fm b/lib/Time.parse_microseconds.fm new file mode 100644 index 00000000..7ad7327f --- /dev/null +++ b/lib/Time.parse_microseconds.fm @@ -0,0 +1,2 @@ +Time.parse_microseconds(ms: U64): U64 + U64.mod(U64.mul(ms, 1000l), 1000l) \ No newline at end of file diff --git a/lib/Time.parse_miliseconds.fm b/lib/Time.parse_miliseconds.fm new file mode 100644 index 00000000..44fce5ea --- /dev/null +++ b/lib/Time.parse_miliseconds.fm @@ -0,0 +1,2 @@ +Time.parse_miliseconds(ms: U64): U64 + U64.mod(ms, 1000l) \ No newline at end of file diff --git a/lib/Time.parse_minutes.fm b/lib/Time.parse_minutes.fm new file mode 100644 index 00000000..576bd836 --- /dev/null +++ b/lib/Time.parse_minutes.fm @@ -0,0 +1,2 @@ +Time.parse_minutes(ms: U64): U64 + U64.mod(U64.div(ms, 60000l), 60l) \ No newline at end of file diff --git a/lib/Time.parse_ms.fm b/lib/Time.parse_ms.fm new file mode 100644 index 00000000..d051fe61 --- /dev/null +++ b/lib/Time.parse_ms.fm @@ -0,0 +1,11 @@ +// Inspired on https://github.com/sindresorhus/parse-ms +Time.parse_ms(ms: U64): Time + Time.new( + Time.parse_days(ms), + Time.parse_hours(ms), + Time.parse_minutes(ms), + Time.parse_seconds(ms), + Time.parse_miliseconds(ms), + Time.parse_microseconds(ms), + Time.parse_nanoseconds(ms) + ) \ No newline at end of file diff --git a/lib/Time.parse_nanoseconds.fm b/lib/Time.parse_nanoseconds.fm new file mode 100644 index 00000000..5fd6ba11 --- /dev/null +++ b/lib/Time.parse_nanoseconds.fm @@ -0,0 +1,2 @@ +Time.parse_nanoseconds(ms: U64): U64 + U64.mod(U64.mul(ms, 1000000l), 1000l) \ No newline at end of file diff --git a/lib/Time.parse_seconds.fm b/lib/Time.parse_seconds.fm new file mode 100644 index 00000000..5c0bfe0b --- /dev/null +++ b/lib/Time.parse_seconds.fm @@ -0,0 +1,2 @@ +Time.parse_seconds(ms: U64): U64 + U64.mod(U64.div(ms, 1000l), 60l) \ No newline at end of file diff --git a/lib/Time.parse_years.fm b/lib/Time.parse_years.fm new file mode 100644 index 00000000..6ac0b11c --- /dev/null +++ b/lib/Time.parse_years.fm @@ -0,0 +1,2 @@ +Time.parse_years(ms: U64): U64 + U64.div(Time.parse_days(ms), 365l) \ No newline at end of file diff --git a/lib/Time.prettify.fm b/lib/Time.prettify.fm new file mode 100644 index 00000000..0a45e738 --- /dev/null +++ b/lib/Time.prettify.fm @@ -0,0 +1,48 @@ +Time.prettify(t: Time, verbose: Bool): String + let time_list = Time.time_to_list(t) + case t: + | let str = "" + let str = + case U64.gtn(t.nanoseconds, 0l): + | let nano = String.concat(Time.show.nanoseconds(t.nanoseconds, verbose), " ") + String.concat(nano, str); + | str; + + let str = + case U64.gtn(t.microseconds, 0l): + | let nano = String.concat(Time.show.microseconds(t.microseconds, verbose), " ") + String.concat(nano, str); + | str; + + let str = + case U64.gtn(t.milliseconds, 0l): + | let nano = String.concat(Time.show.milliseconds(t.milliseconds, verbose), " ") + String.concat(nano, str); + | str; + + let str = + case U64.gtn(t.seconds, 0l): + | let nano = String.concat(Time.show.seconds(t.seconds, verbose), " ") + String.concat(nano, str); + | str; + + let str = + case U64.gtn(t.minutes, 0l): + | let nano = String.concat(Time.show.minutes(t.minutes, verbose), " ") + String.concat(nano, str); + | str; + + let str = + case U64.gtn(t.hours, 0l): + | let nano = String.concat(Time.show.hours(t.hours, verbose), " ") + String.concat(nano, str); + | str; + + let str = + case U64.gtn(t.days, 0l): + | let nano = String.concat(Time.show.days(t.days, verbose), " ") + String.concat(nano, str); + | str; + + str + ; \ No newline at end of file diff --git a/lib/Time.show.fm b/lib/Time.show.fm new file mode 100644 index 00000000..ed7e45f1 --- /dev/null +++ b/lib/Time.show.fm @@ -0,0 +1,60 @@ +Time.show(t: Time, verbose: Bool): Time.stringify + case t: + | let days = Time.show.days(t.days, verbose) + let hours = Time.show.hours(t.hours, verbose) + let mins = Time.show.minutes(t.minutes, verbose) + let secs = Time.show.seconds(t.seconds, verbose) + let mili = Time.show.milliseconds(t.milliseconds, verbose) + let micro = Time.show.microseconds(t.microseconds, verbose) + let nano = Time.show.nanoseconds(t.nanoseconds, verbose) + Time.stringify.new(days, hours, mins, secs, mili, micro, nano) + ; + +Time.show.days(t.days: U64, verbose: Bool): String + case verbose: + | case Bool.or(U64.gtn(t.days, 1l), U64.eql(t.days, 0l)): + | String.concat(U64.show(t.days), " days"); + | String.concat(U64.show(t.days), " day");; + | String.concat(U64.show(t.days), "d"); + +Time.show.hours(t.hours: U64, verbose: Bool): String + case verbose: + | case Bool.or(U64.gtn(t.hours, 1l), U64.eql(t.hours, 0l)): + | String.concat(U64.show(t.hours), " hours"); + | String.concat(U64.show(t.hours), " hour");; + | String.concat(U64.show(t.hours), "h"); + +Time.show.minutes(t.minutes: U64, verbose: Bool): String + case verbose: + | case Bool.or(U64.gtn(t.minutes, 1l), U64.eql(t.minutes, 0l)): + | String.concat(U64.show(t.minutes), " minutes"); + | String.concat(U64.show(t.minutes), " minute");; + | String.concat(U64.show(t.minutes), "m"); + +Time.show.seconds(t.seconds: U64, verbose: Bool): String + case verbose: + | case Bool.or(U64.gtn(t.seconds, 1l), U64.eql(t.seconds, 0l)): + | String.concat(U64.show(t.seconds), " seconds"); + | String.concat(U64.show(t.seconds), " second");; + | String.concat(U64.show(t.seconds), "s"); + +Time.show.milliseconds(t.milliseconds: U64, verbose: Bool): String + case verbose: + | case Bool.or(U64.gtn(t.milliseconds, 1l), U64.eql(t.milliseconds, 0l)): + | String.concat(U64.show(t.milliseconds), " milliseconds"); + | String.concat(U64.show(t.milliseconds), " millisecond");; + | String.concat(U64.show(t.milliseconds), "ms"); + +Time.show.microseconds(t.microseconds: U64, verbose: Bool): String + case verbose: + | case Bool.or(U64.gtn(t.microseconds, 1l), U64.eql(t.microseconds, 0l)): + | String.concat(U64.show(t.microseconds), " microseconds"); + | String.concat(U64.show(t.microseconds), " microsecond");; + | String.concat(U64.show(t.microseconds), "µs"); + +Time.show.nanoseconds(t.nanoseconds: U64, verbose: Bool): String + case verbose: + | case Bool.or(U64.gtn(t.nanoseconds, 1l), U64.eql(t.nanoseconds, 0l)): + | String.concat(U64.show(t.nanoseconds), " nanoseconds"); + | String.concat(U64.show(t.nanoseconds), " nanosecond");; + | String.concat(U64.show(t.nanoseconds), "ns"); \ No newline at end of file diff --git a/lib/Time.stringify.fm b/lib/Time.stringify.fm new file mode 100644 index 00000000..0320ab42 --- /dev/null +++ b/lib/Time.stringify.fm @@ -0,0 +1,9 @@ +T Time.stringify +| Time.stringify.new( + days: String, + hours: String, + minutes: String, + seconds: String, + milliseconds: String, + microseconds: String, + nanoseconds: String); diff --git a/lib/Time.time_to_list.fm b/lib/Time.time_to_list.fm new file mode 100644 index 00000000..3401a26d --- /dev/null +++ b/lib/Time.time_to_list.fm @@ -0,0 +1,11 @@ +Time.time_to_list(t: Time): List(U64) + case t: + | let nano = List.cons<>(t.nanoseconds, List.nil<>) + let micro = List.cons<>(t.microseconds, nano) + let milliseconds = List.cons<>(t.milliseconds, micro) + let seconds = List.cons<>(t.seconds, milliseconds) + let minutes = List.cons<>(t.minutes, seconds) + let hours = List.cons<>(t.hours, minutes) + let days = List.cons<>(t.days, hours) + days + ; \ No newline at end of file diff --git a/lib/U16.max.fm b/lib/U16.max.fm new file mode 100644 index 00000000..488d3642 --- /dev/null +++ b/lib/U16.max.fm @@ -0,0 +1,2 @@ +U16.max: U16 + 65535s \ No newline at end of file diff --git a/lib/U32.max.fm b/lib/U32.max.fm new file mode 100644 index 00000000..472739e6 --- /dev/null +++ b/lib/U32.max.fm @@ -0,0 +1,2 @@ +U32.max: U32 + 4294967295u \ No newline at end of file diff --git a/lib/U64.max.fm b/lib/U64.max.fm new file mode 100644 index 00000000..0a0c58ad --- /dev/null +++ b/lib/U64.max.fm @@ -0,0 +1,2 @@ +U64.max: U64 + 18446744073709551615l \ No newline at end of file diff --git a/lib/U64.show.fm b/lib/U64.show.fm new file mode 100644 index 00000000..f6419c85 --- /dev/null +++ b/lib/U64.show.fm @@ -0,0 +1,3 @@ +// TODO: do a correct U64.show +U64.show(u: U64): String + Nat.show(U64.to_nat(u)) \ No newline at end of file diff --git a/lib/U8.max.fm b/lib/U8.max.fm new file mode 100644 index 00000000..011dad4f --- /dev/null +++ b/lib/U8.max.fm @@ -0,0 +1,2 @@ +U8.max: U8 + 255b \ No newline at end of file