I wanted to track a program and set a maximum runtime for it in a way
which is readable for the user. So I needed to write a time
tansformation which I could use in my track function.
First I wanted to use something like the 'defunits' macro from "Let
over Lambda" from Doug Hoyte, but I'm not so fit in LISP and Clojure
to write/understand it :(.
So I use following two function:
(defn unit-of-time
[value unit]
"(unit-of-time value unit) returns the value in relation to the
defined unit in seconds.
Example: (unit-of-time 10 :minute) will return 600 and (unit-of-time
3 :millisecond) 3/1000.
following Keywords are supported:
:second
:minute
:houre
:day
:millisecond
:microsecond
:nanosecond"
(* value (case unit
:second 1
:minute 60
:houre 3600
:day 86400
:millisecond 1/1000
:microsecond 1/1000000
:nanosecond 1/1000000000)))
(defn transform-time
[value from to]
"(transform-time value from to) calculates the value from the unit
'from' to the unit 'to'"
(/ (unit-of-time value from)
(unit-of-time 1 to)))
The functions, but now I would know if there might be a better way to
transform for example a time value given in minutes into the
appropriate milli- or nanosecond value?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en