I'd suggest using java.util.concurrent.TimeUnit
for example TimeUnit.MILLISECONDS.toDays(1234543211);
or, since we're on Clojure list (.toDays
java.util.concurrent.TimeUnit/MILLISECONDS 1234543211)

For more complex tasks Joda Time is excellent choice.

On Sat, Mar 31, 2012 at 4:51 AM, Goldritter
<marcus.goldritter.lind...@googlemail.com> wrote:
> 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 clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Petr Gladkikh

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to