Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Haskell-mouse/time
1 result
Show changes
Commits on Source (61)
Showing with 175 additions and 146 deletions
......@@ -10,14 +10,14 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
ghc: ['9.0.1', '8.10.7', '8.8.4']
ghc: ['9.2.2', '9.0.2', '8.10.7']
steps:
- uses: actions/checkout@v2
- uses: haskell/actions/setup@v1.2.6
- uses: actions/checkout@v3
- uses: haskell/actions/setup@v2.0.0
id: setup-haskell-cabal
with:
ghc-version: ${{ matrix.ghc }}
- uses: actions/cache@v2.1.6
- uses: actions/cache@v3
name: Cache cabal stuff
with:
path: |
......@@ -42,14 +42,14 @@ jobs:
strategy:
fail-fast: false
matrix:
ghc: ['9.0.1', '8.10.7', '8.8.4']
ghc: ['9.2.2', '9.0.2', '8.10.7']
steps:
- uses: actions/checkout@v2
- uses: haskell/actions/setup@v1.2.6
- uses: actions/checkout@v3
- uses: haskell/actions/setup@v2.0.0
id: setup-haskell-cabal
with:
ghc-version: ${{ matrix.ghc }}
- uses: actions/cache@v2.1.6
- uses: actions/cache@v3
name: Cache cabal stuff
with:
path: |
......@@ -74,12 +74,12 @@ jobs:
build-freebsd:
# See https://github.com/vmactions/freebsd-vm#under-the-hood.
runs-on: macos-latest
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build
id: build-freebsd
uses: vmactions/freebsd-vm@v0.1.5
uses: vmactions/freebsd-vm@v0.1.6
with:
usesh: true
mem: 4096
......
......@@ -5,6 +5,7 @@ conf*
a.out
configure
dist/
dist-newstyle/
dist-install
ghc.mk
lib/include/HsTimeConfig.h
......
......@@ -17,6 +17,7 @@ Before release:
4. Update changelog, add current UTC date
date -u
changelog.md
5. Use latest LTS resolver
......@@ -41,7 +42,7 @@ Before release:
8. Format source
./format-all
./format-all -b
9. Build & test
......@@ -53,7 +54,7 @@ Before release:
11. Inspect generated haddock, if necessary
`stack path --local-doc-root`/index.html
dist/doc/html/time/index.html
12. Commit and push changes to repo
......
TimeLib is Copyright (c) Ashley Yakeley and contributors, 2004-2021. All rights reserved.
TimeLib is Copyright (c) Ashley Yakeley and contributors, 2004-2022. All rights reserved.
Certain sections are Copyright 2004, The University Court of the University of Glasgow. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
......
# FP_DECL_ALTZONE
# ---------------
# Defines HAVE_DECL_ALTZONE to 1 if declared, 0 otherwise.
#
# Used by base package.
AC_DEFUN([FP_DECL_ALTZONE],
[AC_REQUIRE([AC_HEADER_TIME])dnl
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_DECLS([altzone], [], [],[#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif])
])# FP_DECL_ALTZONE
# FP_DECL_ALTZONE
# ---------------
# Defines HAVE_DECL_ALTZONE to 1 if declared, 0 otherwise.
#
# Used by base package.
AC_DEFUN([FP_DECL_ALTZONE],
[
AC_CHECK_HEADERS_ONCE([sys/time.h])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_DECLS([altzone], [], [],[
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>
])
])# FP_DECL_ALTZONE
......@@ -5,3 +5,4 @@ ghcup set ghc latest
cabal v1-install --only-dependencies --enable-tests
cabal v1-configure --enable-tests
cabal v1-test
cabal v1-haddock
packages: time.cabal
tests: true
# Change Log
## [1.12.2] - 2022-05-14
- add weekFirstDay, weekLastDay, weekAllDays
- expose formatting/parsing internals
- fix: handle +HH format for ISO8601 timeOffsetFormat etc.
- fix clock_REALTIME for WebAssembly
## [1.12.1] - 2021-10-24
- add DayPeriod class for periods of days
- add QuarterDay pattern and DayOfQuarter type synonym
......
AC_INIT([Haskell time package],[1.12.1],[ashley@semantic.org],[time])
AC_INIT([Haskell time package],[1.12.2],[ashley@semantic.org],[time])
# Safety check: Ensure that we are in the correct source directory.
AC_CONFIG_SRCDIR([lib/include/HsTime.h])
......
#!/bin/bash -e
stack build --no-test --no-bench --no-haddock fourmolu
for f in `find -name '*.hs' -not -path '*.stack-work/*' -not -path '*/dist/*' | grep -xvf .format.ignore`; do `stack path --local-install-root`/bin/fourmolu -i -o -XPatternSynonyms $f || exit; done
if [ "$1" == "-b" ]
then stack build --no-test --no-bench --no-haddock fourmolu
fi
for f in `find -name '*.hs' -not -path '*.stack-work/*' -not -path '*/dist/*' | grep -xvf .format.ignore`
do `stack path --local-install-root`/bin/fourmolu -i -o -XPatternSynonyms $f || exit
done
respectful: false
haddock-style: single-line
consistent-let: true
......@@ -4,9 +4,9 @@ git pull
autoreconf -i
PATH=$HOME/.ghcup/bin:$PATH
ghcup upgrade
ghcup install cabal latest
ghcup install cabal latest
ghcup set cabal latest
for c in 8.8.4 8.10.7 9.0.1
for c in 8.10.7 9.0.2 9.2.2
do
ghcup install ghc $c
ghcup set ghc $c
......@@ -14,5 +14,6 @@ cabal update
cabal v1-install --only-dependencies --enable-tests
cabal v1-configure --enable-tests
cabal v1-test
cabal v1-haddock
done
echo OK
......@@ -11,7 +11,7 @@ if (!$?) {Exit 1}
if (!$?) {Exit 1}
& "ghcup" "set" "cabal" "latest"
if (!$?) {Exit 1}
ForEach ($c in "8.8.4","8.10.7","9.0.1")
ForEach ($c in "8.10.7","9.0.2","9.2.2")
{
& "ghcup" "install" "ghc" "$c"
if (!$?) {Exit 1}
......@@ -25,5 +25,7 @@ ForEach ($c in "8.8.4","8.10.7","9.0.1")
if (!$?) {Exit 1}
& "cabal" "v1-test"
if (!$?) {Exit 1}
& "cabal" "v1-haddock"
if (!$?) {Exit 1}
}
Echo "OK"
Write-Output "OK"
......@@ -61,10 +61,10 @@ parseReader readp s =
-- | A text format for a type
data Format t = MkFormat
{ -- | Show a value in the format, if representable
formatShowM :: t -> Maybe String
, -- | Read a value in the format
formatReadP :: ReadP t
{ formatShowM :: t -> Maybe String
-- ^ Show a value in the format, if representable
, formatReadP :: ReadP t
-- ^ Read a value in the format
}
-- | Show a value in the format, or error if unrepresentable
......@@ -110,7 +110,8 @@ clipFormat (lo, hi) = filterFormat (\a -> a >= lo && a <= hi)
instance Productish Format where
pUnit = MkFormat{formatShowM = \_ -> Just "", formatReadP = return ()}
(<**>) (MkFormat sa ra) (MkFormat sb rb) =
let sab (a, b) = do
let
sab (a, b) = do
astr <- sa a
bstr <- sb b
return $ astr ++ bstr
......@@ -118,18 +119,20 @@ instance Productish Format where
a <- ra
b <- rb
return (a, b)
in MkFormat sab rab
in MkFormat sab rab
(MkFormat sa ra) **> (MkFormat sb rb) =
let s b = do
let
s b = do
astr <- sa ()
bstr <- sb b
return $ astr ++ bstr
r = do
ra
rb
in MkFormat s r
in MkFormat s r
(MkFormat sa ra) <** (MkFormat sb rb) =
let s a = do
let
s a = do
astr <- sa a
bstr <- sb ()
return $ astr ++ bstr
......@@ -137,43 +140,47 @@ instance Productish Format where
a <- ra
rb
return a
in MkFormat s r
in MkFormat s r
instance Summish Format where
pVoid = MkFormat absurd pfail
(MkFormat sa ra) <++> (MkFormat sb rb) =
let sab (Left a) = sa a
let
sab (Left a) = sa a
sab (Right b) = sb b
rab = (fmap Left ra) +++ (fmap Right rb)
in MkFormat sab rab
in MkFormat sab rab
literalFormat :: String -> Format ()
literalFormat s = MkFormat{formatShowM = \_ -> Just s, formatReadP = string s >> return ()}
specialCaseShowFormat :: Eq a => (a, String) -> Format a -> Format a
specialCaseShowFormat (val, str) (MkFormat s r) =
let s' t
let
s' t
| t == val = Just str
s' t = s t
in MkFormat s' r
in MkFormat s' r
specialCaseFormat :: Eq a => (a, String) -> Format a -> Format a
specialCaseFormat (val, str) (MkFormat s r) =
let s' t
let
s' t
| t == val = Just str
s' t = s t
r' = (string str >> return val) +++ r
in MkFormat s' r'
in MkFormat s' r'
optionalFormat :: Eq a => a -> Format a -> Format a
optionalFormat val = specialCaseFormat (val, "")
casesFormat :: Eq a => [(a, String)] -> Format a
casesFormat pairs =
let s t = lookup t pairs
let
s t = lookup t pairs
r [] = pfail
r ((v, str) : pp) = (string str >> return v) <++ r pp
in MkFormat s $ r pairs
in MkFormat s $ r pairs
optionalSignFormat :: (Eq t, Num t) => Format t
optionalSignFormat = casesFormat [(1, ""), (1, "+"), (0, ""), (-1, "-")]
......@@ -221,10 +228,12 @@ trimTrailing s = s
showNumber :: Show t => SignOption -> Maybe Int -> t -> Maybe String
showNumber signOpt mdigitcount t =
let showIt str =
let (intPart, decPart) = break ((==) '.') str
in (zeroPad mdigitcount intPart) ++ trimTrailing decPart
in case show t of
let
showIt str =
let
(intPart, decPart) = break ((==) '.') str
in (zeroPad mdigitcount intPart) ++ trimTrailing decPart
in case show t of
('-' : str) ->
case signOpt of
NoSign -> Nothing
......
......@@ -82,10 +82,10 @@ periodLength p = succ $ fromInteger $ diffDays (periodLastDay p) (periodFirstDay
--
-- @since 1.12.1
periodFromDay :: DayPeriod p => Day -> (p, Int)
periodFromDay d =
let p = dayPeriod d
dt = succ $ fromInteger $ diffDays d $ periodFirstDay p
in (p, dt)
periodFromDay d = let
p = dayPeriod d
dt = succ $ fromInteger $ diffDays d $ periodFirstDay p
in (p, dt)
-- | Inverse of 'periodFromDay'.
--
......@@ -97,9 +97,9 @@ periodToDay p i = addDays (toInteger $ pred i) $ periodFirstDay p
--
-- @since 1.12.1
periodToDayValid :: DayPeriod p => p -> Int -> Maybe Day
periodToDayValid p i =
let d = periodToDay p i
in if fst (periodFromDay d) == p then Just d else Nothing
periodToDayValid p i = let
d = periodToDay p i
in if fst (periodFromDay d) == p then Just d else Nothing
instance DayPeriod Day where
periodFirstDay = id
......
......@@ -18,7 +18,7 @@ sundayAfter day = addDays (7 - (mod (toModifiedJulianDay day + 3) 7)) day
-- | Given a year, find the Paschal full moon according to Orthodox Christian tradition
orthodoxPaschalMoon :: Year -> Day
orthodoxPaschalMoon year = addDays (- shiftedEpact) (fromJulian jyear 4 19)
orthodoxPaschalMoon year = addDays (-shiftedEpact) (fromJulian jyear 4 19)
where
shiftedEpact = mod (14 + 11 * (mod year 19)) 30
jyear =
......@@ -32,7 +32,7 @@ orthodoxEaster = sundayAfter . orthodoxPaschalMoon
-- | Given a year, find the Paschal full moon according to the Gregorian method
gregorianPaschalMoon :: Year -> Day
gregorianPaschalMoon year = addDays (- adjustedEpact) (fromGregorian year 4 19)
gregorianPaschalMoon year = addDays (-adjustedEpact) (fromGregorian year 4 19)
where
century = (div year 100) + 1
shiftedEpact = mod (14 + 11 * (mod year 19) - (div (3 * century) 4) + (div (5 + 8 * century) 25)) 30
......
......@@ -133,46 +133,46 @@ addGregorianDurationRollOver (CalendarDiffDays m d) day = addDays d $ addGregori
-- | Calendrical difference, with as many whole months as possible
diffGregorianDurationClip :: Day -> Day -> CalendarDiffDays
diffGregorianDurationClip day2 day1 =
let (y1, m1, d1) = toGregorian day1
(y2, m2, d2) = toGregorian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addGregorianDurationClip (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
diffGregorianDurationClip day2 day1 = let
(y1, m1, d1) = toGregorian day1
(y2, m2, d2) = toGregorian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addGregorianDurationClip (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
-- | Calendrical difference, with as many whole months as possible.
-- Same as 'diffGregorianDurationClip' for positive durations.
diffGregorianDurationRollOver :: Day -> Day -> CalendarDiffDays
diffGregorianDurationRollOver day2 day1 =
let (y1, m1, d1) = toGregorian day1
(y2, m2, d2) = toGregorian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addGregorianDurationRollOver (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
diffGregorianDurationRollOver day2 day1 = let
(y1, m1, d1) = toGregorian day1
(y2, m2, d2) = toGregorian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addGregorianDurationRollOver (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
-- orphan instance
instance Show Day where
......
......@@ -125,43 +125,43 @@ addJulianDurationRollOver (CalendarDiffDays m d) day = addDays d $ addJulianMont
-- | Calendrical difference, with as many whole months as possible
diffJulianDurationClip :: Day -> Day -> CalendarDiffDays
diffJulianDurationClip day2 day1 =
let (y1, m1, d1) = toJulian day1
(y2, m2, d2) = toJulian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addJulianDurationClip (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
diffJulianDurationClip day2 day1 = let
(y1, m1, d1) = toJulian day1
(y2, m2, d2) = toJulian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addJulianDurationClip (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
-- | Calendrical difference, with as many whole months as possible.
-- Same as 'diffJulianDurationClip' for positive durations.
diffJulianDurationRollOver :: Day -> Day -> CalendarDiffDays
diffJulianDurationRollOver day2 day1 =
let (y1, m1, d1) = toJulian day1
(y2, m2, d2) = toJulian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addJulianDurationRollOver (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
diffJulianDurationRollOver day2 day1 = let
(y1, m1, d1) = toJulian day1
(y2, m2, d2) = toJulian day2
ym1 = y1 * 12 + toInteger m1
ym2 = y2 * 12 + toInteger m2
ymdiff = ym2 - ym1
ymAllowed =
if day2 >= day1
then
if d2 >= d1
then ymdiff
else ymdiff - 1
else
if d2 <= d1
then ymdiff
else ymdiff + 1
dayAllowed = addJulianDurationRollOver (CalendarDiffDays ymAllowed 0) day1
in CalendarDiffDays ymAllowed $ diffDays day2 dayAllowed
......@@ -53,7 +53,8 @@ fromJulianYearAndDayValid year day = do
else 365
)
day
let y = year - 1
let
y = year - 1
mjd = (fromIntegral day') + (365 * y) + (div y 4) - 678578
return (ModifiedJulianDay mjd)
......
......@@ -47,7 +47,8 @@ monthAndDayToDayOfYearValid :: Bool -> MonthOfYear -> DayOfMonth -> Maybe DayOfY
monthAndDayToDayOfYearValid isLeap month day = do
month' <- clipValid 1 12 month
day' <- clipValid 1 (monthLength' isLeap month') day
let day'' = fromIntegral day'
let
day'' = fromIntegral day'
month'' = fromIntegral month'
k =
if month' <= 2
......@@ -104,4 +105,4 @@ monthLengths isleap =
, 31
]
--J F M A M J J A S O N D
-- J F M A M J J A S O N D