<commit_before>%
% (c) The GRASP/AQUA Project, Glasgow University, 1995-99
%
\section[Time]{Haskell 1.4 Time of Day Library}

The {\em Time} library provides standard functionality for
clock times, including timezone information (i.e, the functionality of
"time.h",  adapted to the Haskell environment), It follows RFC 1129 in
its use of Coordinated Universal Time (UTC).

\begin{code}
{-# OPTIONS -#include "cbits/timezone.h" -#include "cbits/stgio.h"  #-}
module Time 
     (
        Month(..)
     ,  Day(..)

     ,  ClockTime(..) -- non-standard, lib. report gives this as abstract
     ,	getClockTime

     ,  TimeDiff(..)
     ,  noTimeDiff      -- non-standard (but useful when constructing TimeDiff vals.)
     ,  diffClockTimes
     ,  addToClockTime

     ,  timeDiffToString  -- non-standard
     ,  formatTimeDiff    -- non-standard

     ,  CalendarTime(..)
     ,	toCalendarTime
     ,  toUTCTime
     ,  toClockTime
     ,  calendarTimeToString
     ,  formatCalendarTime

     ) where

#ifdef __HUGS__
import PreludeBuiltin
#else
import PrelBase
import PrelShow
import PrelIOBase
import PrelHandle
import PrelArr
import PrelST
import PrelAddr
import PrelNum
import PrelPack 	( unpackCString, new_ps_array,
			  freeze_ps_array, unpackCStringBA
			)
#endif

import Ix
import Char     	( intToDigit )
import Locale

\end{code}

One way to partition and give name to chunks of a year and a week:

\begin{code}
data Month
 = January   | February | March    | April
 | May       | June     | July     | August
 | September | October  | November | December
 deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)

data Day 
 = Sunday   | Monday | Tuesday | Wednesday
 | Thursday | Friday | Saturday
 deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)

\end{code}

@ClockTime@ is an abstract type, used for the internal clock time.
Clock times may be compared, converted to strings, or converted to an
external calendar time @CalendarTime@.

\begin{code}
#ifdef __HUGS__
-- I believe Int64 is more than big enough.
-- In fact, I think one of Int32 or Word32 would do. - ADR
data ClockTime = TOD Int64 Int64 deriving (Eq, Ord)
#else
data ClockTime = TOD Integer Integer deriving (Eq, Ord)
#endif
\end{code}

When a @ClockTime@ is shown, it is converted to a string of the form
@"Mon Nov 28 21:45:41 GMT 1994"@.

For now, we are restricted to roughly:
Fri Dec 13 20:45:52 1901 through Tue Jan 19 03:14:07 2038, because
we use the C library routines based on 32 bit integers.

\begin{code}
#ifdef __HUGS__
#warning Show ClockTime is bogus
instance Show ClockTime
#else
instance Show ClockTime where
    showsPrec p (TOD (S# i) _nsec) = 
      case int2Integer# i of (# s, d #) -> showsPrec p (TOD (J# s d) _nsec)
    showsPrec _ (TOD (J# s# d#) _nsec) = 
      showString $ unsafePerformIO $ do
            let buflen@(I# buflen#) = 50 -- big enough for error message
	    buf <- allocChars buflen 
	    if s# <# (negateInt# 1#) || s# ># 1# then
	       return "ClockTime.show{Time}: out of range"
	     else do<commit_msg>[project @ 1999-11-25 10:37:12 by simonpj] Add a comment<commit_after>%
% (c) The GRASP/AQUA Project, Glasgow University, 1995-99
%
\section[Time]{Haskell 1.4 Time of Day Library}

The {\em Time} library provides standard functionality for
clock times, including timezone information (i.e, the functionality of
"time.h",  adapted to the Haskell environment), It follows RFC 1129 in
its use of Coordinated Universal Time (UTC).

\begin{code}
{-# OPTIONS -#include "cbits/timezone.h" -#include "cbits/stgio.h"  #-}
module Time 
     (
        Month(..)
     ,  Day(..)

     ,  ClockTime(..) -- non-standard, lib. report gives this as abstract
     ,	getClockTime

     ,  TimeDiff(..)
     ,  noTimeDiff      -- non-standard (but useful when constructing TimeDiff vals.)
     ,  diffClockTimes
     ,  addToClockTime

     ,  timeDiffToString  -- non-standard
     ,  formatTimeDiff    -- non-standard

     ,  CalendarTime(..)
     ,	toCalendarTime
     ,  toUTCTime
     ,  toClockTime
     ,  calendarTimeToString
     ,  formatCalendarTime

     ) where

#ifdef __HUGS__
import PreludeBuiltin
#else
import PrelBase
import PrelShow
import PrelIOBase
import PrelHandle
import PrelArr
import PrelST
import PrelAddr
import PrelNum
import PrelPack 	( unpackCString, new_ps_array,
			  freeze_ps_array, unpackCStringBA
			)
#endif

import Ix
import Char     	( intToDigit )
import Locale

\end{code}

One way to partition and give name to chunks of a year and a week:

\begin{code}
data Month
 = January   | February | March    | April
 | May       | June     | July     | August
 | September | October  | November | December
 deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)

data Day 
 = Sunday   | Monday | Tuesday | Wednesday
 | Thursday | Friday | Saturday
 deriving (Eq, Ord, Enum, Bounded, Ix, Read, Show)

\end{code}

@ClockTime@ is an abstract type, used for the internal clock time.
Clock times may be compared, converted to strings, or converted to an
external calendar time @CalendarTime@.

\begin{code}
#ifdef __HUGS__
-- I believe Int64 is more than big enough.
-- In fact, I think one of Int32 or Word32 would do. - ADR
data ClockTime = TOD Int64 Int64 deriving (Eq, Ord)
#else
data ClockTime = TOD Integer 		-- Seconds since 00:00:00 on 1 Jan 1970
		     Integer		-- Picoseconds with the specified second
	       deriving (Eq, Ord)
		
#endif
\end{code}

When a @ClockTime@ is shown, it is converted to a string of the form
@"Mon Nov 28 21:45:41 GMT 1994"@.

For now, we are restricted to roughly:
Fri Dec 13 20:45:52 1901 through Tue Jan 19 03:14:07 2038, because
we use the C library routines based on 32 bit integers.

\begin{code}
#ifdef __HUGS__
#warning Show ClockTime is bogus
instance Show ClockTime
#else
instance Show ClockTime where
    showsPrec p (TOD (S# i) _nsec) = 
      case int2Integer# i of (# s, d #) -> showsPrec p (TOD (J# s d) _nsec)
    showsPrec _ (TOD (J# s# d#) _nsec) = 
      showString $ unsafePerformIO $ do
            let buflen@(I# buflen#) = 50 -- big enough for error message
	    buf <- allocChars buflen 
	    if s# <# (negateInt# 1#) || s# ># 1# then
	       return "ClockTime.show{Time}: out of range"
	     else do
{'fraction_non_alphanumeric': 0.0925238172129824, 'fraction_numerical': 0.0250282577103181, 'mean_word_length': 3.0483660130718953, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2444234', 'n_tokens_mistral': 2222, 'n_tokens_neox': 1985, 'n_words': 760}