Commit 5c2ae5b7 authored by Steffen Michels's avatar Steffen Michels

made mkTime non-pure function & added timeGm for Posic

parent ecd28445
......@@ -56,6 +56,7 @@ read :: !Int !Pointer !Int !*w -> (!Int, !*w)
write :: !Int !{#Char} !Int !*w -> (!Int, !*w)
select_ :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w)
kill :: !Int !Int !*w -> (!Int, !*w)
timegm :: !{#Int} -> Int
//Memory (impure)
malloc :: !Int -> Pointer
......
......@@ -122,6 +122,11 @@ kill pid sig world = code {
ccall kill "II:I:A"
}
timegm :: !{#Int} -> Int
timegm tm = code {
ccall timegm "A:I"
}
malloc :: !Int -> Pointer
malloc num = code {
ccall malloc "p:p"
......
......@@ -60,9 +60,15 @@ gmTime :: !*World -> (!Tm, !*World)
*/
localTime :: !*World -> (!Tm, !*World)
/**
* Convert a Tm record (local time) to a Timestamp value
* Convert a Tm record (local time) to a Timestamp value.
* This is not a pure function as it depends on the current local time zone.
*/
mkTime :: !Tm -> Timestamp
mkTime :: !Tm !*World-> (!Timestamp, !*World)
/**
* Convert a Tm record (UTC) to a Timestamp value.
* No time zone conversion is done.
*/
timeGm :: !Tm -> Timestamp
/**
* Calculate the difference in seconds between two times
*/
......
implementation module System.Time
import StdString, StdArray, StdClass, StdOverloaded, StdInt
import System._Pointer
import System._Pointer, System._Posix
import Text
//String buffer size
......@@ -80,16 +80,19 @@ localTime world
ccall localtime "A:p:p"
}
mkTime :: !Tm -> Timestamp
mkTime tm
# t = mkTimeC (packTm tm)
= Timestamp t
where
mkTimeC :: !{#Int} -> Int
mkTimeC tm = code {
ccall mktime "A:I"
mkTime :: !Tm !*World-> (!Timestamp, !*World)
mkTime tm world
# (t, world) = mkTimeC (packTm tm) world
= (Timestamp t, world)
where
mkTimeC :: !{#Int} !*World -> (!Int, !*World)
mkTimeC tm world = code {
ccall mktime "A:I:A"
}
timeGm :: !Tm -> Timestamp
timeGm tm = Timestamp (timegm (packTm tm))
diffTime :: !Timestamp !Timestamp -> Int
diffTime (Timestamp t1) (Timestamp t2) = t1 - t2
......
......@@ -59,9 +59,10 @@ gmTime :: !*World -> (!Tm, !*World)
*/
localTime :: !*World -> (!Tm, !*World)
/**
* Convert a Tm record (local time) to a Timestamp value
* Convert a Tm record (local time) to a Timestamp value.
* This is not a pure function as it depends on the current local time zone.
*/
mkTime :: !Tm -> Timestamp
mkTime :: !Tm !*World-> (!Timestamp, !*World)
/**
* Calculate the difference in seconds between two times
*/
......
......@@ -74,14 +74,14 @@ localTime world
# (tm,world) = localTimeC (packInt t) world
= (derefTm tm, world)
mkTime :: !Tm -> Timestamp
mkTime tm
# t = mkTimeC (packTm tm)
= Timestamp t
where
mkTimeC :: !{#Int} -> Int
mkTimeC tm = code {
ccall mktime "A:I"
mkTime :: !Tm !*World-> (!Timestamp, !*World)
mkTime tm world
# (t, world) = mkTimeC (packTm tm) world
= (Timestamp t, world)
where
mkTimeC :: !{#Int} !*World -> (!Int, !*World)
mkTimeC tm world = code {
ccall mktime "A:I:I"
}
diffTime :: !Timestamp !Timestamp -> Int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment