
Just in time for HCAR... Please take a look at my second attempt at writing a replacement for the standard time library. http://semantic.org/TimeLib/ Take a look at the Haddock documentation: http://semantic.org/TimeLib/doc/html/ Download the source: http://semantic.org/TimeLib/TimeLib-0.2.tar.gz Or keep up-to-date: darcs get http://semantic.org/TimeLib/TimeLib/ It needs GHC 6.4.1. (I haven't tested with 6.4.) Just run "make" to build the library, tests and documentation. There's also a cabal file (as a completely separate build process), but I've been having trouble with that on Mac OS X. I'm particularly interested in comments from people who try to write little applications for it. What did you have trouble with? What made no sense? Also have a look at some use-cases, which get compiled as part of the package tests: http://semantic.org/TimeLib/TimeLib/test/UseCases.lhs Major changes since 0.1: * Moved to Data.Time, since the actual "System" part (getting the current time and time-zone) is relatively small. * Big simplification of types. Now tuples are used for calendar data (such as (year,month,day) for the Gregorian calendar), and the confusing DayEncoding class has been dropped. Some points: 1. There is no leap second table provided, though there is a type (LeapSecondTable) for such things. Any software compiled with a fixed table would soon become out of date. 2. There is no table of time-zones provided, since these also change. However, if there's a good way of getting this from the TZ database on the machine, I'll add that. It is actually possible to get the local time-zone for any given time, indeed one of the test programs finds your local summertime transitions. The Timezone type includes name, minutes of offset, and a "summertime" flag. 3. The TimeLocale type comes from the already existing System.Locale. 4. It's not possible to expunge POSIX time. Why? Because it's the only way to do sensible arithmetic on UTC times without knowing the leap second table and without worrying about one-second offsets. 5. I include Data.Fixed which provides a fixed-point arithmetic type (wrapper around Integer). It probably should be in a separate package. It allows dealing with seconds as a single thing, rather than as an integer/picoseconds pair. 6. I don't have any text-parsing functionality for times. This is a fair amount of work, so it would be good to know sensible requirements. 7. Time as measured by the CPU since system startup remains in System.CPUTime, which TimeLib does not intend to replace. -- Ashley Yakeley, Seattle WA

On 2005-10-31, Ashley Yakeley
Just in time for HCAR...
Please take a look at my second attempt at writing a replacement for the standard time library. http://semantic.org/TimeLib/
Thanks for your work on that. This is certainly a sore spot in Haskell right now. Your library looks very complete. It also looks over-complicated, IMHO. (Somewhat of the same problem that the current library has). There are just a few functions that a lot of people need, and they are: (C functions in parens) * Convert epoch time to a printable string (ctime) * Convert epoch time to something like struct tm (localtime/gmtime) * Convert a struct tm to epoch time (mktime) * Convert a struct tm to a printable string (asctime) * Get the current time in epoch seconds (time) It all seems overly-complicated to me, and it's not obvious how to do any of these things from the documentation. (Unlike, say, Python -- or even System.Time.) I am also concerned that you have separate types for UTCTime and LocalTime. Many people would consider UTC to be just another zone (Unix does, for instance.) I recognize that there are complicated issues surrounding timekeeping, but the average programmer should not have to worry about those details unless those details are relevant. (They usually are not) Perhaps the solution is a Data.Time.Simple or something that acts as a wrapper. For many programmers, myself included, the Unix epoch is the most common, pervasive, and useful way to work with time. Calculations are simple (no need for various TimeDiff sort of things -- just add on x number of seconds), and it is used *everywhere* in the OS, databases, etc. Something that is based on that, such as the C API, is a plus, IMHO. -- John

On 11/1/05, John Goerzen
On 2005-10-31, Ashley Yakeley
wrote: Just in time for HCAR...
Please take a look at my second attempt at writing a replacement for the standard time library. http://semantic.org/TimeLib/
Thanks for your work on that. This is certainly a sore spot in Haskell right now.
Your library looks very complete. It also looks over-complicated, IMHO. (Somewhat of the same problem that the current library has).
There are just a few functions that a lot of people need, and they are:
(C functions in parens)
* Convert epoch time to a printable string (ctime) * Convert epoch time to something like struct tm (localtime/gmtime) * Convert a struct tm to epoch time (mktime) * Convert a struct tm to a printable string (asctime) * Get the current time in epoch seconds (time)
It all seems overly-complicated to me, and it's not obvious how to do any of these things from the documentation. (Unlike, say, Python -- or even System.Time.)
I am also concerned that you have separate types for UTCTime and LocalTime. Many people would consider UTC to be just another zone (Unix does, for instance.)
I recognize that there are complicated issues surrounding timekeeping, but the average programmer should not have to worry about those details unless those details are relevant. (They usually are not) Perhaps the solution is a Data.Time.Simple or something that acts as a wrapper.
For many programmers, myself included, the Unix epoch is the most common, pervasive, and useful way to work with time. Calculations are simple (no need for various TimeDiff sort of things -- just add on x number of seconds), and it is used *everywhere* in the OS, databases, etc. Something that is based on that, such as the C API, is a plus, IMHO.
I'll just add in another feature request. I sometimes need wall-clock time with very high precision. To meassure the time it takes to run a function say. CPUTime does some of that, but that only meassure the amount of time you use on the CPU, it would be nice to know in "real" time how long it's been between two times. You could use a PerformanceCounter on windows and I'm sure there is something similar on other architectures. SDL has a library which does something like this, unfortunatly they return milliseconds, which is several orders of magnitude less resolution than most internal timers really have. So an Integer (or Int64) returning picosecs (since system boot, program start or something like that) is probably a good somewhat future-proof solution. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

Hello Sebastian, Tuesday, November 01, 2005, 5:21:44 PM, you wrote: SS> I sometimes need wall-clock time with very high precision. To meassure i use the following: diffTimes (TOD sa pa) (TOD sb pb) = fromIntegral(sa - sb) + (fromIntegral(pa-pb) / 1e12) -- Number of seconds since oprogram start return_real_secs = do start_time <- readIORef refClockTimeAtProgramStart current_time <- getClockTime return $ diffTimes current_time start_time of course, it's a hack using internal details of current library and i also need the function which will return high-precision wall-clock time -- Best regards, Bulat mailto:bulatz@HotPOP.com

On 11/1/05, Bulat Ziganshin
Hello Sebastian,
Tuesday, November 01, 2005, 5:21:44 PM, you wrote:
SS> I sometimes need wall-clock time with very high precision. To meassure
i use the following:
diffTimes (TOD sa pa) (TOD sb pb) = fromIntegral(sa - sb) + (fromIntegral(pa-pb) / 1e12)
-- Number of seconds since oprogram start return_real_secs = do start_time <- readIORef refClockTimeAtProgramStart current_time <- getClockTime return $ diffTimes current_time start_time
of course, it's a hack using internal details of current library and i also need the function which will return high-precision wall-clock time
Well, on my system, System.Time has a resolution of 16ms, which is terrible. So we need a function that uses the various high performance counters that each architecture exposes to get high-precison results. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

On Tue, 1 Nov 2005, Sebastian Sylvan wrote:
Well, on my system, System.Time has a resolution of 16ms, which is terrible.
So we need a function that uses the various high performance counters that each architecture exposes to get high-precison results.
Those counters are not synchronized to civil time. You can't have both
high resolution and absolute precision.
Tony.
--
f.a.n.finch

On 11/1/05, Tony Finch
On Tue, 1 Nov 2005, Sebastian Sylvan wrote:
Well, on my system, System.Time has a resolution of 16ms, which is terrible.
So we need a function that uses the various high performance counters that each architecture exposes to get high-precison results.
Those counters are not synchronized to civil time. You can't have both high resolution and absolute precision.
Which is why I requested a separate function which just gives the picosecs since startup (or something). -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

In article
<3d96ac180511010738h1e3c5206vba7318e724e3cb48@mail.gmail.com>,
Sebastian Sylvan
Which is why I requested a separate function which just gives the picosecs since startup (or something).
That's what getCPUTime in System.CPUTime does. -- Ashley Yakeley, Seattle WA

On 11/2/05, Ashley Yakeley
In article <3d96ac180511010738h1e3c5206vba7318e724e3cb48@mail.gmail.com>, Sebastian Sylvan
wrote: Which is why I requested a separate function which just gives the picosecs since startup (or something).
That's what getCPUTime in System.CPUTime does.
No it isnt'. getCPUTime gives the.. uh.. CPU-time :-) If all my program does is sleep, waiting for other programs to release some resource, then getCPUTime will return zero. What I'm requesting is a function which gives the number of wall-clock picos seconds since startup, which could be used for all sorts of real-time simulations etc. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

On Wed, Nov 02, 2005 at 11:43:16AM +0100, Sebastian Sylvan wrote:
On 11/2/05, Ashley Yakeley
wrote: In article <3d96ac180511010738h1e3c5206vba7318e724e3cb48@mail.gmail.com>, Sebastian Sylvan
wrote: Which is why I requested a separate function which just gives the picosecs since startup (or something).
That's what getCPUTime in System.CPUTime does.
No it isnt'. getCPUTime gives the.. uh.. CPU-time :-)
If all my program does is sleep, waiting for other programs to release some resource, then getCPUTime will return zero.
What I'm requesting is a function which gives the number of wall-clock picos seconds since startup, which could be used for all sorts of real-time simulations etc.
is this true? I always thought that is what getCPUTime was supposed to mean, a reading from the tsc on x86 machines for instance and distinct from the unix notion of 'cputime'. John -- John Meacham - ⑆repetae.net⑆john⑈

On Wed, Nov 02, 2005 at 08:19:56PM -0800, John Meacham wrote:
On Wed, Nov 02, 2005 at 11:43:16AM +0100, Sebastian Sylvan wrote:
On 11/2/05, Ashley Yakeley
wrote: In article <3d96ac180511010738h1e3c5206vba7318e724e3cb48@mail.gmail.com>, Sebastian Sylvan
wrote: Which is why I requested a separate function which just gives the picosecs since startup (or something).
That's what getCPUTime in System.CPUTime does.
No it isnt'. getCPUTime gives the.. uh.. CPU-time :-)
If all my program does is sleep, waiting for other programs to release some resource, then getCPUTime will return zero.
What I'm requesting is a function which gives the number of wall-clock picos seconds since startup, which could be used for all sorts of real-time simulations etc.
is this true? I always thought that is what getCPUTime was supposed to mean, a reading from the tsc on x86 machines for instance and distinct from the unix notion of 'cputime'.
hmm.. looking at the report, you are correct. hmm.. perhaps we need another function to read the tsc-equivalent on various CPUs. -- John Meacham - ⑆repetae.net⑆john⑈

In article
There are just a few functions that a lot of people need, and they are:
These can all be done easily if you use UTCTime for epoch time.
(C functions in parens)
* Convert epoch time to a printable string (ctime)
ctime :: UTCTime -> String ctime t = show (utcToLocalTime utc t) TODO: add a "Show UTCTime" instance, allowing ctime = show
* Convert epoch time to something like struct tm (localtime/gmtime)
gmtime :: UTCTime -> ZonedTime gmtime = zonedTimeFromUTC utc TODO: rename zonedTimeFromUTC to utcToZonedTime. Depending on exactly what you want it to do, localtime is one of these: -- use time zone at given time localtime :: UTCTime -> IO ZonedTime localtime = utcToLocalZonedTime -- use time zone at current time localtime' :: UTCTime -> IO ZonedTime localtime' t = do zone <- getCurrentTimeZone zonedTimeFromUTC zone t The current time zone is different at different times according to the summertime rule. It's possible to find out what it is for a given time.
* Convert a struct tm to epoch time (mktime)
mktime :: ZonedTime -> UTCTime mktime = ztUTC TODO: rename ztUTC to something more sensible.
* Convert a struct tm to a printable string (asctime)
asctime = ZonedTime -> String asctime = show
* Get the current time in epoch seconds (time)
time :: IO UTCTime time = getCurrentTime
For many programmers, myself included, the Unix epoch is the most common, pervasive, and useful way to work with time. Calculations are simple (no need for various TimeDiff sort of things -- just add on x number of seconds), and it is used *everywhere* in the OS, databases, etc. Something that is based on that, such as the C API, is a plus, IMHO.
Simon Marlow seems to be generally of the opinion that POSIX time is evil and should be expunged (because it's a broken representation of UTC). I do however have a few POSIX functions exposed. My UTCTime is more or less the simplest correct representation (consisting of a day count and a time offset). I think UTCTime should remain the main representation of UTC time, but perhaps there should be another module (Data.Time.POSIX) for people who need to muck about with seconds since epoch. It would have POSIXTime with arithmetic, conversion to UTCTime, and getting the current time. Thanks... -- Ashley Yakeley, Seattle WA
participants (6)
-
Ashley Yakeley
-
Bulat Ziganshin
-
John Goerzen
-
John Meacham
-
Sebastian Sylvan
-
Tony Finch