module Music.Theory.Time.Notation where
import Text.Printf
import qualified Data.List.Split as Split
import qualified Data.Time as Time
import qualified Music.Theory.Function as Function
import qualified Music.Theory.List as List
type Week = Int
type Day = Int
type Hour = Int
type Min = Int
type Sec = Int
type Csec = Int
type MinSec = (Min,Sec)
type GMinSec n = (n,n)
type MinCsec = (Min,Sec,Csec)
type GMinCsec n = (n,n,n)
type Hms = (Hour,Min,Sec)
type Dhms = (Day,Hour,Min,Sec)
type FDay = Double
type FHour = Double
type FMin = Double
type FSec = Double
type FMinSec = Double
parse_time_str :: Time.ParseTime t => String -> String -> t
parse_time_str :: forall t. ParseTime t => String -> String -> t
parse_time_str = forall t.
ParseTime t =>
Bool -> TimeLocale -> String -> String -> t
Time.parseTimeOrError Bool
True TimeLocale
Time.defaultTimeLocale
format_time_str :: Time.FormatTime t => String -> t -> String
format_time_str :: forall t. FormatTime t => String -> t -> String
format_time_str = forall t. FormatTime t => TimeLocale -> String -> t -> String
Time.formatTime TimeLocale
Time.defaultTimeLocale
parse_iso8601_date :: String -> Time.UTCTime
parse_iso8601_date :: String -> UTCTime
parse_iso8601_date String
s =
case forall (t :: * -> *) a. Foldable t => t a -> Sec
length String
s of
Sec
8 -> forall t. ParseTime t => String -> String -> t
parse_time_str String
"%Y%m%d" String
s
Sec
10 -> forall t. ParseTime t => String -> String -> t
parse_time_str String
"%F" String
s
Sec
_ -> forall a. HasCallStack => String -> a
error String
"parse_iso8601_date?"
format_iso8601_date :: Time.FormatTime t => Bool -> t -> String
format_iso8601_date :: forall t. FormatTime t => Bool -> t -> String
format_iso8601_date Bool
ext = if Bool
ext then forall t. FormatTime t => String -> t -> String
format_time_str String
"%F" else forall t. FormatTime t => String -> t -> String
format_time_str String
"%Y%m%d"
format_iso8601_week :: Time.FormatTime t => t -> String
format_iso8601_week :: forall t. FormatTime t => t -> String
format_iso8601_week = forall t. FormatTime t => String -> t -> String
format_time_str String
"%G-W%V"
parse_iso8601_time :: String -> Time.UTCTime
parse_iso8601_time :: String -> UTCTime
parse_iso8601_time String
s =
case forall (t :: * -> *) a. Foldable t => t a -> Sec
length String
s of
Sec
6 -> forall t. ParseTime t => String -> String -> t
parse_time_str String
"%H%M%S" String
s
Sec
8 -> forall t. ParseTime t => String -> String -> t
parse_time_str String
"%H:%M:%S" String
s
Sec
_ -> forall a. HasCallStack => String -> a
error String
"parse_iso8601_time?"
format_iso8601_time :: Time.FormatTime t => Bool -> t -> String
format_iso8601_time :: forall t. FormatTime t => Bool -> t -> String
format_iso8601_time Bool
ext = forall t. FormatTime t => String -> t -> String
format_time_str (if Bool
ext then String
"%H:%M:%S" else String
"%H%M%S")
parse_iso8601_date_time :: String -> Time.UTCTime
parse_iso8601_date_time :: String -> UTCTime
parse_iso8601_date_time String
s =
case forall (t :: * -> *) a. Foldable t => t a -> Sec
length String
s of
Sec
15 -> forall t. ParseTime t => String -> String -> t
parse_time_str String
"%Y%m%dT%H%M%S" String
s
Sec
19 -> forall t. ParseTime t => String -> String -> t
parse_time_str String
"%FT%H:%M:%S" String
s
Sec
_ -> forall a. HasCallStack => String -> a
error (String
"parse_iso8601_date_time: " forall a. [a] -> [a] -> [a]
++ String
s)
format_iso8601_date_time :: Time.FormatTime t => Bool -> t -> String
format_iso8601_date_time :: forall t. FormatTime t => Bool -> t -> String
format_iso8601_date_time Bool
ext = forall t. FormatTime t => String -> t -> String
format_time_str (if Bool
ext then String
"%FT%H:%M:%S" else String
"%Y%m%dT%H%M%S")
fmin_to_minsec :: FMin -> MinSec
fmin_to_minsec :: FSec -> MinSec
fmin_to_minsec = FSec -> MinSec
fsec_to_minsec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => a -> a -> a
(*) FSec
60
fsec_to_picoseconds :: FSec -> Integer
fsec_to_picoseconds :: FSec -> Integer
fsec_to_picoseconds FSec
s = forall a b. (RealFrac a, Integral b) => a -> b
floor (FSec
s forall a. Num a => a -> a -> a
* (FSec
10 forall a. Floating a => a -> a -> a
** FSec
12))
fsec_to_difftime :: FSec -> Time.DiffTime
fsec_to_difftime :: FSec -> DiffTime
fsec_to_difftime = Integer -> DiffTime
Time.picosecondsToDiffTime forall b c a. (b -> c) -> (a -> b) -> a -> c
. FSec -> Integer
fsec_to_picoseconds
fminsec_to_fsec :: FMinSec -> FSec
fminsec_to_fsec :: FSec -> FSec
fminsec_to_fsec FSec
n =
let m :: FSec
m = FSec -> FSec
ffloor FSec
n
s :: FSec
s = (FSec
n forall a. Num a => a -> a -> a
- FSec
m) forall a. Num a => a -> a -> a
* FSec
100
in (FSec
m forall a. Num a => a -> a -> a
* FSec
60) forall a. Num a => a -> a -> a
+ FSec
s
fminsec_to_sec_generic :: (RealFrac f,Integral i) => f -> i
fminsec_to_sec_generic :: forall f i. (RealFrac f, Integral i) => f -> i
fminsec_to_sec_generic f
n =
let m :: i
m = forall a b. (RealFrac a, Integral b) => a -> b
floor f
n
s :: i
s = forall a b. (RealFrac a, Integral b) => a -> b
round ((f
n forall a. Num a => a -> a -> a
- forall a b. (Integral a, Num b) => a -> b
fromIntegral i
m) forall a. Num a => a -> a -> a
* f
100)
in (i
m forall a. Num a => a -> a -> a
* i
60) forall a. Num a => a -> a -> a
+ i
s
fminsec_to_sec :: FMinSec -> Sec
fminsec_to_sec :: FSec -> Sec
fminsec_to_sec = forall f i. (RealFrac f, Integral i) => f -> i
fminsec_to_sec_generic
fsec_to_fminsec :: FSec -> FMinSec
fsec_to_fminsec :: FSec -> FSec
fsec_to_fminsec FSec
n =
let m :: FSec
m = FSec -> FSec
ffloor (FSec
n forall a. Fractional a => a -> a -> a
/ FSec
60)
s :: FSec
s = FSec
n forall a. Num a => a -> a -> a
- (FSec
m forall a. Num a => a -> a -> a
* FSec
60)
in FSec
m forall a. Num a => a -> a -> a
+ (FSec
s forall a. Fractional a => a -> a -> a
/ FSec
100)
sec_to_fminsec :: Sec -> FMinSec
sec_to_fminsec :: Sec -> FSec
sec_to_fminsec Sec
n =
let m :: FSec
m = FSec -> FSec
ffloor (forall a b. (Integral a, Num b) => a -> b
fromIntegral Sec
n forall a. Fractional a => a -> a -> a
/ FSec
60)
s :: FSec
s = forall a b. (Integral a, Num b) => a -> b
fromIntegral Sec
n forall a. Num a => a -> a -> a
- (FSec
m forall a. Num a => a -> a -> a
* FSec
60)
in FSec
m forall a. Num a => a -> a -> a
+ (FSec
s forall a. Fractional a => a -> a -> a
/ FSec
100)
fminsec_add :: Function.BinOp FMinSec
fminsec_add :: BinOp FSec
fminsec_add FSec
p FSec
q = FSec -> FSec
fsec_to_fminsec (FSec -> FSec
fminsec_to_fsec FSec
p forall a. Num a => a -> a -> a
+ FSec -> FSec
fminsec_to_fsec FSec
q)
fminsec_sub :: Function.BinOp FMinSec
fminsec_sub :: BinOp FSec
fminsec_sub FSec
p FSec
q = FSec -> FSec
fsec_to_fminsec (FSec -> FSec
fminsec_to_fsec FSec
p forall a. Num a => a -> a -> a
- FSec -> FSec
fminsec_to_fsec FSec
q)
fminsec_mul :: Function.BinOp FMinSec
fminsec_mul :: BinOp FSec
fminsec_mul FSec
t FSec
n = FSec -> FSec
fsec_to_fminsec (FSec -> FSec
fminsec_to_fsec FSec
t forall a. Num a => a -> a -> a
* FSec
n)
ffloor :: Double -> Double
ffloor :: FSec -> FSec
ffloor = forall a. Num a => Integer -> a
fromInteger forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (RealFrac a, Integral b) => a -> b
floor
fhour_to_hms :: FHour -> Hms
fhour_to_hms :: FSec -> Hms
fhour_to_hms FSec
h =
let m :: FSec
m = (FSec
h forall a. Num a => a -> a -> a
- FSec -> FSec
ffloor FSec
h) forall a. Num a => a -> a -> a
* FSec
60
s :: FSec
s = (FSec
m forall a. Num a => a -> a -> a
- FSec -> FSec
ffloor FSec
m) forall a. Num a => a -> a -> a
* FSec
60
in (forall a b. (RealFrac a, Integral b) => a -> b
floor FSec
h,forall a b. (RealFrac a, Integral b) => a -> b
floor FSec
m,forall a b. (RealFrac a, Integral b) => a -> b
round FSec
s)
hms_to_fhour :: Hms -> FHour
hms_to_fhour :: Hms -> FSec
hms_to_fhour (Sec
h,Sec
m,Sec
s) = forall a b. (Integral a, Num b) => a -> b
fromIntegral Sec
h forall a. Num a => a -> a -> a
+ (forall a b. (Integral a, Num b) => a -> b
fromIntegral Sec
m forall a. Fractional a => a -> a -> a
/ FSec
60) forall a. Num a => a -> a -> a
+ (forall a b. (Integral a, Num b) => a -> b
fromIntegral Sec
s forall a. Fractional a => a -> a -> a
/ (FSec
60 forall a. Num a => a -> a -> a
* FSec
60))
fhour_to_fsec :: FHour -> FSec
fhour_to_fsec :: FSec -> FSec
fhour_to_fsec = forall a. Num a => a -> a -> a
(*) (FSec
60 forall a. Num a => a -> a -> a
* FSec
60)
fhour_to_difftime :: FHour -> Time.DiffTime
fhour_to_difftime :: FSec -> DiffTime
fhour_to_difftime = FSec -> DiffTime
fsec_to_difftime forall b c a. (b -> c) -> (a -> b) -> a -> c
. FSec -> FSec
fhour_to_fsec
utctime_to_fday :: Time.UTCTime -> FDay
utctime_to_fday :: UTCTime -> FSec
utctime_to_fday UTCTime
t =
let d :: Day
d = UTCTime -> Day
Time.utctDay UTCTime
t
d' :: FSec
d' = forall a b. (Integral a, Num b) => a -> b
fromIntegral (Day -> Integer
Time.toModifiedJulianDay Day
d)
s :: DiffTime
s = UTCTime -> DiffTime
Time.utctDayTime UTCTime
t
s_max :: FSec
s_max = FSec
86401
in FSec
d' forall a. Num a => a -> a -> a
+ (forall a. Fractional a => Rational -> a
fromRational (forall a. Real a => a -> Rational
toRational DiffTime
s) forall a. Fractional a => a -> a -> a
/ FSec
s_max)
difftime_to_fsec :: Time.DiffTime -> FSec
difftime_to_fsec :: DiffTime -> FSec
difftime_to_fsec = forall a. Fractional a => Rational -> a
fromRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Real a => a -> Rational
toRational
difftime_to_fmin :: Time.DiffTime -> Double
difftime_to_fmin :: DiffTime -> FSec
difftime_to_fmin = (forall a. Fractional a => a -> a -> a
/ FSec
60) forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> FSec
difftime_to_fsec
difftime_to_fhour :: Time.DiffTime -> FHour
difftime_to_fhour :: DiffTime -> FSec
difftime_to_fhour = (forall a. Fractional a => a -> a -> a
/ FSec
60) forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> FSec
difftime_to_fmin
hms_to_difftime :: Hms -> Time.DiffTime
hms_to_difftime :: Hms -> DiffTime
hms_to_difftime = FSec -> DiffTime
fhour_to_difftime forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hms -> FSec
hms_to_fhour
hms_to_sec :: Hms -> Sec
hms_to_sec :: Hms -> Sec
hms_to_sec (Sec
h,Sec
m,Sec
s) = Sec
h forall a. Num a => a -> a -> a
* Sec
60 forall a. Num a => a -> a -> a
* Sec
60 forall a. Num a => a -> a -> a
+ Sec
m forall a. Num a => a -> a -> a
* Sec
60 forall a. Num a => a -> a -> a
+ Sec
s
sec_to_hms :: Sec -> Hms
sec_to_hms :: Sec -> Hms
sec_to_hms Sec
s =
let (Sec
h,Sec
s') = Sec
s forall a. Integral a => a -> a -> (a, a)
`divMod` (Sec
60 forall a. Num a => a -> a -> a
* Sec
60)
(Sec
m,Sec
s'') = forall n. Integral n => n -> GMinSec n
sec_to_minsec Sec
s'
in (Sec
h,Sec
m,Sec
s'')
hms_pp :: Bool -> Hms -> String
hms_pp :: Bool -> Hms -> String
hms_pp Bool
trunc (Sec
h,Sec
m,Sec
s) =
if Bool
trunc Bool -> Bool -> Bool
&& Sec
h forall a. Eq a => a -> a -> Bool
== Sec
0
then forall r. PrintfType r => String -> r
printf String
"%02d:%02d" Sec
m Sec
s
else forall r. PrintfType r => String -> r
printf String
"%02d:%02d:%02d" Sec
h Sec
m Sec
s
hms_parse :: String -> Hms
hms_parse :: String -> Hms
hms_parse String
x =
case forall a. Eq a => [a] -> [a] -> [[a]]
Split.splitOn String
":" String
x of
[String
h,String
m,String
s] -> (forall a. Read a => String -> a
read String
h,forall a. Read a => String -> a
read String
m,forall a. Read a => String -> a
read String
s)
[String]
_ -> forall a. HasCallStack => String -> a
error String
"parse_hms"
sec_to_minsec :: Integral n => n -> GMinSec n
sec_to_minsec :: forall n. Integral n => n -> GMinSec n
sec_to_minsec = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Integral a => a -> a -> (a, a)
divMod n
60
minsec_to_sec :: Num n => GMinSec n -> n
minsec_to_sec :: forall n. Num n => GMinSec n -> n
minsec_to_sec (n
m,n
s) = n
m forall a. Num a => a -> a -> a
* n
60 forall a. Num a => a -> a -> a
+ n
s
minsec_binop :: Integral t => (t -> t -> t) -> GMinSec t -> GMinSec t -> GMinSec t
minsec_binop :: forall t.
Integral t =>
(t -> t -> t) -> GMinSec t -> GMinSec t -> GMinSec t
minsec_binop t -> t -> t
f GMinSec t
p GMinSec t
q = forall n. Integral n => n -> GMinSec n
sec_to_minsec (t -> t -> t
f (forall n. Num n => GMinSec n -> n
minsec_to_sec GMinSec t
p) (forall n. Num n => GMinSec n -> n
minsec_to_sec GMinSec t
q))
minsec_sub :: Integral n => GMinSec n -> GMinSec n -> GMinSec n
minsec_sub :: forall n. Integral n => GMinSec n -> GMinSec n -> GMinSec n
minsec_sub = forall t.
Integral t =>
(t -> t -> t) -> GMinSec t -> GMinSec t -> GMinSec t
minsec_binop (-)
minsec_diff :: Integral n => GMinSec n -> GMinSec n -> GMinSec n
minsec_diff :: forall n. Integral n => GMinSec n -> GMinSec n -> GMinSec n
minsec_diff = forall t.
Integral t =>
(t -> t -> t) -> GMinSec t -> GMinSec t -> GMinSec t
minsec_binop forall a. Num a => a -> a -> a
subtract
minsec_add :: Integral n => GMinSec n -> GMinSec n -> GMinSec n
minsec_add :: forall n. Integral n => GMinSec n -> GMinSec n -> GMinSec n
minsec_add = forall t.
Integral t =>
(t -> t -> t) -> GMinSec t -> GMinSec t -> GMinSec t
minsec_binop forall a. Num a => a -> a -> a
(+)
minsec_sum :: Integral n => [GMinSec n] -> GMinSec n
minsec_sum :: forall n. Integral n => [GMinSec n] -> GMinSec n
minsec_sum = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl forall n. Integral n => GMinSec n -> GMinSec n -> GMinSec n
minsec_add (n
0,n
0)
fsec_to_minsec :: FSec -> MinSec
fsec_to_minsec :: FSec -> MinSec
fsec_to_minsec = forall n. Integral n => n -> GMinSec n
sec_to_minsec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (RealFrac a, Integral b) => a -> b
round
minsec_pp :: MinSec -> String
minsec_pp :: MinSec -> String
minsec_pp (Sec
m,Sec
s) = forall r. PrintfType r => String -> r
printf String
"%02d:%02d" Sec
m Sec
s
minsec_parse :: (Num n,Read n) => String -> GMinSec n
minsec_parse :: forall n. (Num n, Read n) => String -> GMinSec n
minsec_parse String
x =
case forall a. Eq a => [a] -> [a] -> [[a]]
Split.splitOn String
":" String
x of
[String
m,String
s] -> (forall a. Read a => String -> a
read String
m,forall a. Read a => String -> a
read String
s)
[String]
_ -> forall a. HasCallStack => String -> a
error (String
"minsec_parse: " forall a. [a] -> [a] -> [a]
++ String
x)
fsec_to_mincsec :: FSec -> MinCsec
fsec_to_mincsec :: FSec -> Hms
fsec_to_mincsec FSec
tm =
let tm' :: Sec
tm' = forall a b. (RealFrac a, Integral b) => a -> b
floor FSec
tm
(Sec
m,Sec
s) = forall n. Integral n => n -> GMinSec n
sec_to_minsec Sec
tm'
cs :: Sec
cs = forall a b. (RealFrac a, Integral b) => a -> b
round ((FSec
tm forall a. Num a => a -> a -> a
- forall a b. (Integral a, Num b) => a -> b
fromIntegral Sec
tm') forall a. Num a => a -> a -> a
* FSec
100)
in (Sec
m,Sec
s,Sec
cs)
mincsec_to_fsec :: Real n => GMinCsec n -> FSec
mincsec_to_fsec :: forall n. Real n => GMinCsec n -> FSec
mincsec_to_fsec (n
m,n
s,n
cs) = forall a b. (Real a, Fractional b) => a -> b
realToFrac n
m forall a. Num a => a -> a -> a
* FSec
60 forall a. Num a => a -> a -> a
+ forall a b. (Real a, Fractional b) => a -> b
realToFrac n
s forall a. Num a => a -> a -> a
+ (forall a b. (Real a, Fractional b) => a -> b
realToFrac n
cs forall a. Fractional a => a -> a -> a
/ FSec
100)
mincsec_to_csec :: Num n => GMinCsec n -> n
mincsec_to_csec :: forall n. Num n => GMinCsec n -> n
mincsec_to_csec (n
m,n
s,n
cs) = n
m forall a. Num a => a -> a -> a
* n
60 forall a. Num a => a -> a -> a
* n
100 forall a. Num a => a -> a -> a
+ n
s forall a. Num a => a -> a -> a
* n
100 forall a. Num a => a -> a -> a
+ n
cs
csec_to_mincsec :: Integral n => n -> GMinCsec n
csec_to_mincsec :: forall n. Integral n => n -> GMinCsec n
csec_to_mincsec n
csec =
let (n
m,n
cs) = n
csec forall a. Integral a => a -> a -> (a, a)
`divMod` n
6000
(n
s,n
cs') = n
cs forall a. Integral a => a -> a -> (a, a)
`divMod` n
100
in (n
m,n
s,n
cs')
mincsec_pp_opt :: Bool -> MinCsec -> String
mincsec_pp_opt :: Bool -> Hms -> String
mincsec_pp_opt Bool
concise (Sec
m,Sec
s,Sec
cs) =
if Bool
concise Bool -> Bool -> Bool
&& Sec
cs forall a. Eq a => a -> a -> Bool
== Sec
0
then forall r. PrintfType r => String -> r
printf String
"%02d:%02d" Sec
m Sec
s
else forall r. PrintfType r => String -> r
printf String
"%02d:%02d.%02d" Sec
m Sec
s Sec
cs
mincsec_pp :: MinCsec -> String
mincsec_pp :: Hms -> String
mincsec_pp = Bool -> Hms -> String
mincsec_pp_opt Bool
False
mincsec_binop :: Integral t => (t -> t -> t) -> GMinCsec t -> GMinCsec t -> GMinCsec t
mincsec_binop :: forall t.
Integral t =>
(t -> t -> t) -> GMinCsec t -> GMinCsec t -> GMinCsec t
mincsec_binop t -> t -> t
f GMinCsec t
p GMinCsec t
q = forall n. Integral n => n -> GMinCsec n
csec_to_mincsec (t -> t -> t
f (forall n. Num n => GMinCsec n -> n
mincsec_to_csec GMinCsec t
p) (forall n. Num n => GMinCsec n -> n
mincsec_to_csec GMinCsec t
q))
sec_to_dhms_generic :: Integral n => n -> (n,n,n,n)
sec_to_dhms_generic :: forall n. Integral n => n -> (n, n, n, n)
sec_to_dhms_generic n
n =
let (n
d,n
h') = n
n forall a. Integral a => a -> a -> (a, a)
`divMod` (n
24 forall a. Num a => a -> a -> a
* n
60 forall a. Num a => a -> a -> a
* n
60)
(n
h,n
m') = n
h' forall a. Integral a => a -> a -> (a, a)
`divMod` (n
60 forall a. Num a => a -> a -> a
* n
60)
(n
m,n
s) = n
m' forall a. Integral a => a -> a -> (a, a)
`divMod` n
60
in (n
d,n
h,n
m,n
s)
sec_to_dhms :: Sec -> Dhms
sec_to_dhms :: Sec -> Dhms
sec_to_dhms = forall n. Integral n => n -> (n, n, n, n)
sec_to_dhms_generic
dhms_to_sec :: Num n => (n,n,n,n) -> n
dhms_to_sec :: forall n. Num n => (n, n, n, n) -> n
dhms_to_sec (n
d,n
h,n
m,n
s) = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [n
d forall a. Num a => a -> a -> a
* n
24 forall a. Num a => a -> a -> a
* n
60 forall a. Num a => a -> a -> a
* n
60,n
h forall a. Num a => a -> a -> a
* n
60 forall a. Num a => a -> a -> a
* n
60,n
m forall a. Num a => a -> a -> a
* n
60,n
s]
parse_dhms_generic :: (Integral n,Read n) => String -> (n,n,n,n)
parse_dhms_generic :: forall n. (Integral n, Read n) => String -> (n, n, n, n)
parse_dhms_generic =
let sep_elem :: String -> String -> [String]
sep_elem = forall a. Splitter a -> [a] -> [[a]]
Split.split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
Split.keepDelimsR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
Split.oneOf
sep_last :: [b] -> ([b], b)
sep_last [b]
x = let (b
e, [b]
x') = forall a. [a] -> (a, [a])
List.headTail (forall a. [a] -> [a]
reverse [b]
x) in (forall a. [a] -> [a]
reverse [b]
x',b
e)
p :: String -> a
p String
x = case forall {b}. [b] -> ([b], b)
sep_last String
x of
(String
n,Char
'd') -> forall a. Read a => String -> a
read String
n forall a. Num a => a -> a -> a
* a
24 forall a. Num a => a -> a -> a
* a
60 forall a. Num a => a -> a -> a
* a
60
(String
n,Char
'h') -> forall a. Read a => String -> a
read String
n forall a. Num a => a -> a -> a
* a
60 forall a. Num a => a -> a -> a
* a
60
(String
n,Char
'm') -> forall a. Read a => String -> a
read String
n forall a. Num a => a -> a -> a
* a
60
(String
n,Char
's') -> forall a. Read a => String -> a
read String
n
(String, Char)
_ -> forall a. HasCallStack => String -> a
error String
"parse_dhms"
in forall n. Integral n => n -> (n, n, n, n)
sec_to_dhms_generic forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall {a}. (Num a, Read a) => String -> a
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Bool
null) forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> [String]
sep_elem String
"dhms"
parse_dhms :: String -> Dhms
parse_dhms :: String -> Dhms
parse_dhms = forall n. (Integral n, Read n) => String -> (n, n, n, n)
parse_dhms_generic
time_to_week :: Time.UTCTime -> Week
time_to_week :: UTCTime -> Sec
time_to_week = forall a. Read a => String -> a
read forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. FormatTime t => String -> t -> String
format_time_str String
"%V"
span_pp :: (t -> String) -> (t,t) -> String
span_pp :: forall t. (t -> String) -> (t, t) -> String
span_pp t -> String
f (t
t1,t
t2) = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [t -> String
f t
t1,String
" - ",t -> String
f t
t2]