[commit: packages/time] master, wip/travis: use cases (as test) (68e172c)

git at git.haskell.org git at git.haskell.org
Sat May 7 06:42:12 UTC 2016


Repository : ssh://git@git.haskell.org/time

On branches: master,wip/travis
Link       : http://git.haskell.org/packages/time.git/commitdiff/68e172c2fb6f6c2374edd3e759fb68499cb38e51

>---------------------------------------------------------------

commit 68e172c2fb6f6c2374edd3e759fb68499cb38e51
Author: Ashley Yakeley <ashley at semantic.org>
Date:   Mon Aug 8 01:16:52 2005 -0700

    use cases (as test)
    
    darcs-hash:20050808081652-ac6dd-a158d7e515bb01a942d39803b9eb5251db29ac9b


>---------------------------------------------------------------

68e172c2fb6f6c2374edd3e759fb68499cb38e51
 TimeLib.xcodeproj/project.pbxproj |  2 +
 test/Makefile                     |  5 ++-
 test/UseCases.lhs                 | 82 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/TimeLib.xcodeproj/project.pbxproj b/TimeLib.xcodeproj/project.pbxproj
index f4f5ca6..89c8c9b 100644
--- a/TimeLib.xcodeproj/project.pbxproj
+++ b/TimeLib.xcodeproj/project.pbxproj
@@ -108,6 +108,7 @@
 		AB2666F108A572520059DEC0 /* Time.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.haskell; path = Time.hs; sourceTree = "<group>"; };
 		AB26682008A5FF0D0059DEC0 /* AddDays.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.haskell; path = AddDays.hs; sourceTree = "<group>"; };
 		AB26682108A5FF0D0059DEC0 /* AddDays.ref */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AddDays.ref; sourceTree = "<group>"; };
+		AB26689F08A6D7290059DEC0 /* UseCases.lhs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.haskell.literate; path = UseCases.lhs; sourceTree = "<group>"; };
 		ABD6783F084167B900CF37C0 /* POSIX.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.haskell; path = POSIX.hs; sourceTree = "<group>"; };
 		ABD67840084167D100CF37C0 /* Current.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.haskell; path = Current.hs; sourceTree = "<group>"; };
 		ABD67841084168B700CF37C0 /* UTC.hs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.haskell; path = UTC.hs; sourceTree = "<group>"; };
@@ -231,6 +232,7 @@
 				ABFA262B083B28C00096540C /* TestFormatStuff.h */,
 				ABFA262A083B28C00096540C /* TestFormatStuff.c */,
 				ABFA2629083B28C00096540C /* TestFormat.hs */,
+				AB26689F08A6D7290059DEC0 /* UseCases.lhs */,
 			);
 			name = Test;
 			path = test;
diff --git a/test/Makefile b/test/Makefile
index 3e8fddd..034e2f4 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -36,7 +36,7 @@ TimeZone: TimeZone.o ../libTimeLib.a
 TimeZone.ref: FORCE
 	date +%z > $@
 
-test: TestFixed.diff ConvertBack.diff0 TestTime.diff LongWeekYears.diff ClipDates.diff AddDays.diff TimeZone.diff TestFormat.diff0
+test: TestFixed.diff ConvertBack.diff0 TestTime.diff LongWeekYears.diff ClipDates.diff AddDays.diff TimeZone.diff TestFormat.diff0 UseCases.o
 
 clean:
 	rm -rf ConvertBack TimeZone TimeZone.ref CurrentTime TestTime TestFixed ShowDST TestFormat *.out *.o *.hi Makefile.bak
@@ -59,6 +59,9 @@ clean:
 %.o: %.hs
 	ghc -i.. -c $< -o $@
 
+%.o: %.lhs
+	ghc -i.. -c $< -o $@
+
 FORCE:
 
 .SECONDARY:
diff --git a/test/UseCases.lhs b/test/UseCases.lhs
new file mode 100644
index 0000000..3db8834
--- /dev/null
+++ b/test/UseCases.lhs
@@ -0,0 +1,82 @@
+> module UseCases where
+> import Data.Time
+> import System.Locale
+
+
+From Brian Smith:
+<http://www.haskell.org/pipermail/libraries/2005-July/004060.html>
+
+Use cases (primarily taken from real-world corporate IT applications I have 
+developed) :
+
+* What is the equivalent (or closest aproximation) of the SQL DateTime type 
+(date and time without any timezone information)? What is the equivalent of 
+the SQL Date type (date without any timezone information)?
+
+> type SQLDateTime = LocalTime
+> type SQLDate = Day
+
+* The user enters a date as "7/4/2005." How do I determine if this date is 
+before or after July 1st of this year?
+
+TODO: Parsing
+
+* How do I present the date "July 1st of this year" to the user in M/D/YYYY 
+format?
+
+> july1st = do
+>    now <- getZonedTime
+>    let (thisYear,_,_) = toGregorian (localDay (ztLocalTime now))
+>    let day = fromGregorian thisYear 7 1
+>    return (formatTime defaultTimeLocale "%m/%d/%Y" day)
+
+This actually gives "07/01/2005" rather than "7/1/2005".
+ISSUE: Should I make additional %-codes for this?
+
+
+* How do I truncate a datetime to midnight of the same day? How do I 
+truncate a date to the first of the month? How do I truncate a date to the 
+first day of the year it occurred in?
+
+> truncateToMidnight (LocalTime day _) = (LocalTime day midnight)
+
+> truncateToFirstOfMonth day = fromGregorian y m 1 where
+>    (y,m,_) = toGregorian day
+
+> truncateToJan1st day = fromYearAndDay y 1 where
+>    (y,_) = toYearAndDay day
+
+* Given a date X, how do I find the last day of the month that X occurs in. 
+For example, If X is July 4th, 2005, then I want the result to be July 31st, 
+2005. If X is Februrary 5, then I want the result to be Februrary 28 for 
+non-leap-years and February 29 for leap years.
+
+> lastDayOfMonth day = fromGregorian y m (gregorianMonthLength y m) where
+>    (y,m,_) = toGregorian day
+
+* The user enters a time T with no date, e.g. "17:30". How do I merge this 
+time onto a date D (e.g. July 4, 2005), so that the result has is a datetime 
+with date D and the time T (July 4, 2005 at 17:30).
+
+> mergeDateAndTime = LocalTime
+
+* Given two datetimes T1, T2, how do I determine if they are on the same 
+date?
+
+> sameDay (LocalTime d1 _) (LocalTime d2 _) = d1 == d2
+
+
+From Simon Marlow:
+<http://www.haskell.org/pipermail/libraries/2005-July/004066.html>
+
+I just had a little look around, mainly at System.Time.Calendar.  I
+think the structure is rather complicated - I wanted to find out how to
+get a CalendarTime for "this time tomorrow", and ended up with this:
+
+*System.Time.Calendar> let c' =
+c{ztTime=zttime{dtDay=dtday{gregDay=day+1}}} where { zttime = ztTime c;
+dtday = dtDay zttime; day = gregDay dtday }
+
+> thisTimeTomorrow (ZonedTime (LocalTime day tod) zone) = (ZonedTime (LocalTime (addDays 1 day) tod) zone)
+
+



More information about the ghc-commits mailing list