[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:54:13 UTC 2010


The following commit has been merged in the master branch:
commit 2c1c15db16ed3d978bbae58685ccab6118477271
Author: John Goerzen <jgoerzen at complete.org>
Date:   Fri Jan 21 08:15:10 2005 +0100

    Added Time.hs
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.7--patch-172)

diff --git a/ChangeLog b/ChangeLog
index a300c4a..6cd07d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,22 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.7
 #
 
+2005-01-21 01:15:10 GMT	John Goerzen <jgoerzen at complete.org>	patch-172
+
+    Summary:
+      Added Time.hs
+    Revision:
+      missingh--head--0.7--patch-172
+
+
+    new files:
+     libsrc/MissingH/Time.hs testsrc/Timetest.hs
+
+    modified files:
+     ChangeLog Setup.description libsrc/MissingH/Printf.hs
+     libsrc/MissingH/Printf/Types.hs testsrc/Tests.hs
+
+
 2004-12-24 02:32:23 GMT	John Goerzen <jgoerzen at complete.org>	patch-171
 
     Summary:
diff --git a/Setup.description b/Setup.description
index 6598dd2..25dacaa 100644
--- a/Setup.description
+++ b/Setup.description
@@ -16,6 +16,7 @@ Modules: MissingH.IO, MissingH.IO.Binary, MissingH.List,
   MissingH.Str,
   MissingH.Cmd,
   MissingH.FiniteMap, MissingH.Path, MissingH.Path.NameManip,
+  MissingH.Time,
   MissingH.Network,
     MissingH.Network.FTP.Client,
     MissingH.Network.FTP.ParserClient,
diff --git a/libsrc/MissingH/Printf.hs b/libsrc/MissingH/Printf.hs
index bc63332..ef9cfe4 100644
--- a/libsrc/MissingH/Printf.hs
+++ b/libsrc/MissingH/Printf.hs
@@ -36,6 +36,14 @@ Inspiration and ideas from haskell-xml-rpc by Bjorn Bringert
 
 Please scroll down to read the detailed documentation.
 
+/NOTE/: to compile this module under ghc, you must use:
+
+> -fallow-overlapping-instances
+
+With hugs:
+
+> -98 +o
+
 -}
 
 module MissingH.Printf(-- * Introduction
@@ -81,7 +89,8 @@ module MissingH.Printf(-- * Introduction
                        -- $fullexamples
 
                        -- * Underlying Types
-                       Value(..)
+                       Value(..),
+                       PFType(..)
                        ) where
 
 import MissingH.Str
diff --git a/libsrc/MissingH/Printf/Types.hs b/libsrc/MissingH/Printf/Types.hs
index 9ce65f2..7b75977 100644
--- a/libsrc/MissingH/Printf/Types.hs
+++ b/libsrc/MissingH/Printf/Types.hs
@@ -46,6 +46,7 @@ import Data.FiniteMap
 
 -- data Wrapped a = Wrapped a
 
+{- | All items to be printed must be expressible as one of these. -}
 data Value =
            ValueRational Rational
            | ValueString String
@@ -57,6 +58,9 @@ showValue (ValueRational x) = show x
 showValue (ValueChar x) = [x]
 showValue (ValueString x) = x
 
+{- | The class to which all items must belong (unless you want to inconvenience
+everyone and force them to manually generate 'Value's.
+-}
 class PFType a where
     toValue :: a -> Value
     fromValue :: Value -> a
diff --git a/libsrc/MissingH/Time.hs b/libsrc/MissingH/Time.hs
new file mode 100644
index 0000000..f94984a
--- /dev/null
+++ b/libsrc/MissingH/Time.hs
@@ -0,0 +1,73 @@
+{- arch-tag: Time utilities main file
+Copyright (C) 2004 John Goerzen <jgoerzen at complete.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-}
+
+{- |
+   Module     : MissingH.Time
+   Copyright  : Copyright (C) 2004 John Goerzen
+   License    : GNU GPL, version 2 or above
+
+   Maintainer : John Goerzen, 
+   Maintainer : jgoerzen at complete.org
+   Stability  : provisional
+   Portability: portable
+
+This module provides various helpful utilities for dealing with times and
+dates.
+
+Written by John Goerzen, jgoerzen\@complete.org
+-}
+
+module MissingH.Time(
+                     calendarTimeUTCToEpoch,
+                     timeDiffToSecs
+                    )
+where
+import System.Time
+
+{- | January 1, 1970 represented as a CalendarTime. -}
+epoch :: CalendarTime
+epoch = CalendarTime { ctYear = 1970, ctMonth = January,
+                       ctDay = 1, ctHour = 0, ctMin = 0, ctSec = 0,
+                       ctPicosec = 0, ctWDay = Thursday, ctYDay = 0,
+                       ctTZName = "", ctTZ = 0, ctIsDST = False}
+
+{- | Converts the specified CalendarTime (see System.Time) to seconds-since-epoch time.
+
+The conversion is naive with respect to timezones.  All timezone and DST information
+in the CalendarTime object is silently ignored.  The epoch is assumed to be
+00:00 on January 1, 1970.
+
+One convenient side-effect of this zone-agnostic approach is that you will
+get proper results out of this function whether or not you pass it UTC data,
+since effectively it is computing a difference. -}
+
+calendarTimeUTCToEpoch :: CalendarTime -> Integer
+calendarTimeUTCToEpoch ct =
+    timeDiffToSecs (diffClockTimes (toClockTime ct) (toClockTime epoch))
+    
+{- | Converts the given timeDiff to the number of seconds it represents. 
+
+Uses the same algorithm as normalizeTimeDiff in GHC. -}
+timeDiffToSecs :: TimeDiff -> Integer
+timeDiffToSecs td = 
+    (fromIntegral $ tdSec td) +
+    60 * ((fromIntegral $ tdMin td) +
+          60 * ((fromIntegral $ tdHour td) +
+                24 * ((fromIntegral $ tdDay td) +
+                      30 * ((fromIntegral $ tdMonth td) +
+                            365 * (fromIntegral $ tdYear td)))))
diff --git a/testsrc/Tests.hs b/testsrc/Tests.hs
index 54b320b..ba9862e 100644
--- a/testsrc/Tests.hs
+++ b/testsrc/Tests.hs
@@ -35,12 +35,14 @@ import qualified CRC32GZIPtest
 import qualified GZiptest
 import qualified HVIOtest
 import qualified HVFStest
+import qualified Timetest
 
 test1 = TestCase ("x" @=? "x")
 
 tests = TestList [TestLabel "test1" test1,
                  TestLabel "List" Listtest.tests,
                  TestLabel "Str" Strtest.tests,
+                 TestLabel "Time" Timetest.tests,
                  TestLabel "FiniteMap" FiniteMaptest.tests,
                  TestLabel "Path" Pathtest.tests,
                  TestLabel "HVIO" HVIOtest.tests,
diff --git a/testsrc/CRC32POSIXtest.hs b/testsrc/Timetest.hs
similarity index 52%
copy from testsrc/CRC32POSIXtest.hs
copy to testsrc/Timetest.hs
index 8f831fa..10b1a95 100644
--- a/testsrc/CRC32POSIXtest.hs
+++ b/testsrc/Timetest.hs
@@ -1,4 +1,4 @@
-{- arch-tag: Tests for CRC-32 module
+{- arch-tag: Time tests main file
 Copyright (C) 2004 John Goerzen <jgoerzen at complete.org>
 
 This program is free software; you can redistribute it and/or modify
@@ -16,21 +16,23 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 -}
 
-module CRC32POSIXtest(tests) where
+module Timetest(tests) where
 import HUnit
-import MissingH.Checksum.CRC32.Posix
-
-test_crc32 =
-    let f msg inp exp = TestLabel msg $ TestCase $ assertEqual "" exp (crc32 inp) in
+import MissingH.Time
+import System.Time
+
+base =CalendarTime {ctYear = 2005, ctMonth = January, ctDay = 21,
+                          ctHour = 1, ctMin = 1, ctSec = 20,
+                          ctPicosec = 0, ctWDay = Sunday, ctYDay = 0,
+                          ctTZName = "", ctTZ = 0, ctIsDST = False}
+test_ct2e =
+    let f base exp = TestLabel (show base) $ TestCase $ exp @=? calendarTimeUTCToEpoch base in
         [
-         f "Empty" "" 4294967295,
-         f "1" "1" 433426081,
-         f "some numbers" "153141341309874102987412" 2083856642,
-         f "Some text" "This is a test of the crc32 thing\n" 2449124888
+         f (base {ctYear = 2005, ctMonth = January, ctDay = 21,
+                          ctHour = 1, ctMin = 1, ctSec = 20})
+           1106269280
 
         ]
 
-tests = TestList [TestLabel "crc32" (TestList test_crc32)
-
-                 ]
-
+tests = TestList [TestLabel "ct2e" (TestList test_ct2e)
+                 ]
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list