    {-# LINE 2 "./System/Glib/GDateTime.chs" #-}
    -- -*-haskell-*-
    -- GIMP Toolkit (GTK)
    --
    -- Author : Peter Gavin
    --
    -- Created: July 2007
    --
    -- Copyright (C) 2007 Peter Gavin
    --
    -- This library is free software; you can redistribute it and/or
    -- modify it under the terms of the GNU Lesser General Public
    -- License as published by the Free Software Foundation; either
    -- version 2.1 of the License, or (at your option) any later version.
    --
    -- This library 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
    -- Lesser General Public License for more details.
    --
    -- |
    -- Maintainer : gtk2hs-users@lists.sourceforge.net
    -- Stability : provisional
    -- Portability : portable (depends on GHC)
    --
    module System.Glib.GDateTime (
      GTimeValPart,
      GTimeVal(..),
      gGetCurrentTime,
      gUSleep,
      gTimeValAdd,

      gTimeValFromISO8601,
      gTimeValToISO8601,

      GDate(..),
      GDateDay,
      GDateMonth,
      GDateYear,
      GDateJulianDay,
      GDateWeekday,
      gDateValidJulian,
      gDateValidDMY,
      gDateNewJulian,
      gDateNewDMY,
      gDateSetDay,
      gDateSetMonth,
      gDateSetYear,

      gDateNewTimeVal,

      gDateParse,
      gDateAddDays,
      gDateSubtractDays,
      gDateAddMonths,
      gDateSubtractMonths,
      gDateAddYears,
      gDateSubtractYears,
      gDateDaysBetween,
      gDateCompare,
      gDateClamp,
      gDateDay,
      gDateMonth,
      gDateYear,
      gDateWeekday
      ) where

    import Control.Monad (liftM)
    import System.Glib.FFI
    import System.Glib.UTFString

    type GTimeValPart = (CLong)
    {-# LINE 73 "./System/Glib/GDateTime.chs" #-}
    data GTimeVal = GTimeVal { gTimeValSec :: GTimeValPart
                             , gTimeValUSec :: GTimeValPart }
                    deriving (Eq, Ord)
    instance Storable GTimeVal where
        sizeOf :: GTimeVal -> Int
    sizeOf GTimeVal
    _ = Int
    16
    {-# LINE 78 "./System/Glib/GDateTime.chs" #-}
        alignment _ = alignment (undefined :: CString)
        peek :: Ptr GTimeVal -> IO GTimeVal
    peek Ptr GTimeVal
    ptr =
            do GTimeValPart
    sec <- (\Ptr GTimeVal
    ptr -> do {Ptr GTimeVal -> Int -> IO GTimeValPart
    forall b. Ptr b -> Int -> IO GTimeValPart
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr GTimeVal
    ptr Int
    0 ::IO CLong}) Ptr GTimeVal
    ptr
               GTimeValPart
    uSec <- (\Ptr GTimeVal
    ptr -> do {Ptr GTimeVal -> Int -> IO GTimeValPart
    forall b. Ptr b -> Int -> IO GTimeValPart
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr GTimeVal
    ptr Int
    8 ::IO CLong}) Ptr GTimeVal
    ptr
               GTimeVal -> IO GTimeVal
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (GTimeVal -> IO GTimeVal) -> GTimeVal -> IO GTimeVal
    forall a b. (a -> b) -> a -> b
    $ GTimeValPart -> GTimeValPart -> GTimeVal
    GTimeVal GTimeValPart
    sec GTimeValPart
    uSec
        poke :: Ptr GTimeVal -> GTimeVal -> IO ()
    poke Ptr GTimeVal
    ptr (GTimeVal GTimeValPart
    sec GTimeValPart
    uSec) =
            do (\Ptr GTimeVal
    ptr GTimeValPart
    val -> do {Ptr GTimeVal -> Int -> GTimeValPart -> IO ()
    forall b. Ptr b -> Int -> GTimeValPart -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr GTimeVal
    ptr Int
    0 (GTimeValPart
    val::CLong)}) Ptr GTimeVal
    ptr GTimeValPart
    sec
               (\Ptr GTimeVal
    ptr GTimeValPart
    val -> do {Ptr GTimeVal -> Int -> GTimeValPart -> IO ()
    forall b. Ptr b -> Int -> GTimeValPart -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr GTimeVal
    ptr Int
    8 (GTimeValPart
    val::CLong)}) Ptr GTimeVal
    ptr GTimeValPart
    uSec

    gGetCurrentTime :: IO GTimeVal
    gGetCurrentTime :: IO GTimeVal
    gGetCurrentTime =
        (Ptr GTimeVal -> IO GTimeVal) -> IO GTimeVal
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr GTimeVal -> IO GTimeVal) -> IO GTimeVal)
    -> (Ptr GTimeVal -> IO GTimeVal) -> IO GTimeVal
    forall a b. (a -> b) -> a -> b
    $ \Ptr GTimeVal
    ptr ->
            do Ptr () -> IO ()
    g_get_current_time (Ptr () -> IO ()) -> Ptr () -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Ptr GTimeVal -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GTimeVal
    ptr
               Ptr GTimeVal -> IO GTimeVal
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GTimeVal
    ptr

    gUSleep :: GTimeValPart
            -> IO ()
    gUSleep :: GTimeValPart -> IO ()
    gUSleep GTimeValPart
    microseconds =
        CULong -> IO ()
    g_usleep (CULong -> IO ()) -> CULong -> IO ()
    forall a b. (a -> b) -> a -> b
    $ GTimeValPart -> CULong
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GTimeValPart
    microseconds

    gTimeValAdd :: GTimeVal
                -> GTimeValPart
                -> GTimeVal
    gTimeValAdd :: GTimeVal -> GTimeValPart -> GTimeVal
    gTimeValAdd GTimeVal
    time GTimeValPart
    microseconds =
        IO GTimeVal -> GTimeVal
    forall a. IO a -> a
    unsafePerformIO (IO GTimeVal -> GTimeVal) -> IO GTimeVal -> GTimeVal
    forall a b. (a -> b) -> a -> b
    $ GTimeVal -> (Ptr GTimeVal -> IO GTimeVal) -> IO GTimeVal
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GTimeVal
    time ((Ptr GTimeVal -> IO GTimeVal) -> IO GTimeVal)
    -> (Ptr GTimeVal -> IO GTimeVal) -> IO GTimeVal
    forall a b. (a -> b) -> a -> b
    $ \Ptr GTimeVal
    ptr ->
            do Ptr () -> GTimeValPart -> IO ()
    g_time_val_add (Ptr GTimeVal -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GTimeVal
    ptr) GTimeValPart
    microseconds
               Ptr GTimeVal -> IO GTimeVal
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GTimeVal
    ptr

    gTimeValFromISO8601 :: GlibString string
                        => string
                        -> Maybe GTimeVal
    gTimeValFromISO8601 :: forall string. GlibString string => string -> Maybe GTimeVal
    gTimeValFromISO8601 string
    isoDate =
        IO (Maybe GTimeVal) -> Maybe GTimeVal
    forall a. IO a -> a
    unsafePerformIO (IO (Maybe GTimeVal) -> Maybe GTimeVal)
    -> IO (Maybe GTimeVal) -> Maybe GTimeVal
    forall a b. (a -> b) -> a -> b
    $ string -> (CString -> IO (Maybe GTimeVal)) -> IO (Maybe GTimeVal)
    forall a. string -> (CString -> IO a) -> IO a
    forall s a. GlibString s => s -> (CString -> IO a) -> IO a
    withUTFString string
    isoDate ((CString -> IO (Maybe GTimeVal)) -> IO (Maybe GTimeVal))
    -> (CString -> IO (Maybe GTimeVal)) -> IO (Maybe GTimeVal)
    forall a b. (a -> b) -> a -> b
    $ \CString
    cISODate ->
            (Ptr GTimeVal -> IO (Maybe GTimeVal)) -> IO (Maybe GTimeVal)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr GTimeVal -> IO (Maybe GTimeVal)) -> IO (Maybe GTimeVal))
    -> (Ptr GTimeVal -> IO (Maybe GTimeVal)) -> IO (Maybe GTimeVal)
    forall a b. (a -> b) -> a -> b
    $ \Ptr GTimeVal
    ptr ->
                do Bool
    success <- (CInt -> Bool) -> IO CInt -> IO Bool
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM CInt -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
    forall a b. (a -> b) -> a -> b
    $ CString -> Ptr () -> IO CInt
    g_time_val_from_iso8601 CString
    cISODate (Ptr () -> IO CInt) -> Ptr () -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Ptr GTimeVal -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GTimeVal
    ptr
                   if Bool
    success
                       then (GTimeVal -> Maybe GTimeVal) -> IO GTimeVal -> IO (Maybe GTimeVal)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM GTimeVal -> Maybe GTimeVal
    forall a. a -> Maybe a
    Just (IO GTimeVal -> IO (Maybe GTimeVal))
    -> IO GTimeVal -> IO (Maybe GTimeVal)
    forall a b. (a -> b) -> a -> b
    $ Ptr GTimeVal -> IO GTimeVal
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GTimeVal
    ptr
                       else Maybe GTimeVal -> IO (Maybe GTimeVal)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe GTimeVal
    forall a. Maybe a
    Nothing

    gTimeValToISO8601 :: GlibString string
                      => GTimeVal
                      -> string
    gTimeValToISO8601 :: forall string. GlibString string => GTimeVal -> string
    gTimeValToISO8601 GTimeVal
    time =
        IO string -> string
    forall a. IO a -> a
    unsafePerformIO (IO string -> string) -> IO string -> string
    forall a b. (a -> b) -> a -> b
    $ GTimeVal -> (Ptr GTimeVal -> IO string) -> IO string
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GTimeVal
    time ((Ptr GTimeVal -> IO string) -> IO string)
    -> (Ptr GTimeVal -> IO string) -> IO string
    forall a b. (a -> b) -> a -> b
    $ \Ptr GTimeVal
    ptr ->
            Ptr () -> IO CString
    g_time_val_to_iso8601 (Ptr GTimeVal -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GTimeVal
    ptr) IO CString -> (CString -> IO string) -> IO string
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= CString -> IO string
    forall s. GlibString s => CString -> IO s
    readUTFString

    newtype GDateDay = GDateDay (CUChar)
    {-# LINE 127 "./System/Glib/GDateTime.chs" #-}
        deriving (Eq, Ord)
    instance Bounded GDateDay where
        minBound :: GDateDay
    minBound = CUChar -> GDateDay
    GDateDay CUChar
    1
        maxBound :: GDateDay
    maxBound = CUChar -> GDateDay
    GDateDay CUChar
    31

    data GDateMonth = GDateBadMonth
                    | GDateJanuary
                    | GDateFebruary
                    | GDateMarch
                    | GDateApril
                    | GDateMay
                    | GDateJune
                    | GDateJuly
                    | GDateAugust
                    | GDateSeptember
                    | GDateOctober
                    | GDateNovember
                    | GDateDecember
                    deriving (GDateMonth -> GDateMonth -> Bool
    (GDateMonth -> GDateMonth -> Bool)
    -> (GDateMonth -> GDateMonth -> Bool) -> Eq GDateMonth
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: GDateMonth -> GDateMonth -> Bool
    == :: GDateMonth -> GDateMonth -> Bool
    $c/= :: GDateMonth -> GDateMonth -> Bool
    /= :: GDateMonth -> GDateMonth -> Bool
    Eq,Eq GDateMonth
    Eq GDateMonth =>
    (GDateMonth -> GDateMonth -> Ordering)
    -> (GDateMonth -> GDateMonth -> Bool)
    -> (GDateMonth -> GDateMonth -> Bool)
    -> (GDateMonth -> GDateMonth -> Bool)
    -> (GDateMonth -> GDateMonth -> Bool)
    -> (GDateMonth -> GDateMonth -> GDateMonth)
    -> (GDateMonth -> GDateMonth -> GDateMonth)
    -> Ord GDateMonth
    GDateMonth -> GDateMonth -> Bool
    GDateMonth -> GDateMonth -> Ordering
    GDateMonth -> GDateMonth -> GDateMonth
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: GDateMonth -> GDateMonth -> Ordering
    compare :: GDateMonth -> GDateMonth -> Ordering
    $c< :: GDateMonth -> GDateMonth -> Bool
    < :: GDateMonth -> GDateMonth -> Bool
    $c<= :: GDateMonth -> GDateMonth -> Bool
    <= :: GDateMonth -> GDateMonth -> Bool
    $c> :: GDateMonth -> GDateMonth -> Bool
    > :: GDateMonth -> GDateMonth -> Bool
    $c>= :: GDateMonth -> GDateMonth -> Bool
    >= :: GDateMonth -> GDateMonth -> Bool
    $cmax :: GDateMonth -> GDateMonth -> GDateMonth
    max :: GDateMonth -> GDateMonth -> GDateMonth
    $cmin :: GDateMonth -> GDateMonth -> GDateMonth
    min :: GDateMonth -> GDateMonth -> GDateMonth
    Ord)
    instance Enum GDateMonth where
      fromEnum GDateBadMonth = 0
      fromEnum GDateJanuary = 1
      fromEnum GDateFebruary = 2
      fromEnum GDateMarch = 3
      fromEnum GDateApril = 4
      fromEnum GDateMay = 5
      fromEnum GDateJune = 6
      fromEnum GDateJuly = 7
      fromEnum GDateAugust = 8
      fromEnum GDateSeptember = 9
      fromEnum GDateOctober = 10
      fromEnum GDateNovember = 11
      fromEnum GDateDecember = 12

      toEnum 0 = GDateBadMonth
      toEnum 1 = GDateJanuary
      toEnum 2 = GDateFebruary
      toEnum 3 = GDateMarch
      toEnum 4 = GDateApril
      toEnum 5 = GDateMay
      toEnum 6 = GDateJune
      toEnum 7 = GDateJuly
      toEnum 8 = GDateAugust
      toEnum 9 = GDateSeptember
      toEnum 10 = GDateOctober
      toEnum 11 = GDateNovember
      toEnum 12 = GDateDecember
      toEnum unmatched = error ("GDateMonth.toEnum: Cannot match " ++ show unmatched)

      succ GDateBadMonth = GDateJanuary
      succ GDateJanuary = GDateFebruary
      succ GDateFebruary = GDateMarch
      succ GDateMarch = GDateApril
      succ GDateApril = GDateMay
      succ GDateMay = GDateJune
      succ GDateJune = GDateJuly
      succ GDateJuly = GDateAugust
      succ GDateAugust = GDateSeptember
      succ GDateSeptember = GDateOctober
      succ GDateOctober = GDateNovember
      succ GDateNovember = GDateDecember
      succ _ = undefined

      pred GDateJanuary = GDateBadMonth
      pred GDateFebruary = GDateJanuary
      pred GDateMarch = GDateFebruary
      pred GDateApril = GDateMarch
      pred GDateMay = GDateApril
      pred GDateJune = GDateMay
      pred GDateJuly = GDateJune
      pred GDateAugust = GDateJuly
      pred GDateSeptember = GDateAugust
      pred GDateOctober = GDateSeptember
      pred GDateNovember = GDateOctober
      pred GDateDecember = GDateNovember
      pred _ = undefined

      enumFromTo x y | fromEnum x == fromEnum y = [ y ]
                     | otherwise = x : enumFromTo (succ x) y
      enumFrom :: GDateMonth -> [GDateMonth]
    enumFrom GDateMonth
    x = GDateMonth -> GDateMonth -> [GDateMonth]
    forall a. Enum a => a -> a -> [a]
    enumFromTo GDateMonth
    x GDateMonth
    GDateDecember
      enumFromThen :: GDateMonth -> GDateMonth -> [GDateMonth]
    enumFromThen GDateMonth
    _ GDateMonth
    _ =     [Char] -> [GDateMonth]
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "Enum GDateMonth: enumFromThen not implemented"
      enumFromThenTo :: GDateMonth -> GDateMonth -> GDateMonth -> [GDateMonth]
    enumFromThenTo GDateMonth
    _ GDateMonth
    _ GDateMonth
    _ =     [Char] -> [GDateMonth]
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "Enum GDateMonth: enumFromThenTo not implemented"

    {-# LINE 133 "./System/Glib/GDateTime.chs" #-}
    instance Bounded GDateMonth where
        minBound = GDateJanuary
        maxBound = GDateDecember

    newtype GDateYear = GDateYear (CUShort)
    {-# LINE 138 "./System/Glib/GDateTime.chs" #-}
        deriving (Eq, Ord)
    instance Bounded GDateYear where
        minBound = GDateYear 1
        maxBound = GDateYear (maxBound :: (CUShort))

    type GDateJulianDay = (CUInt)
    {-# LINE 144 "./System/Glib/GDateTime.chs" #-}
    newtype GDate = GDate { gDateJulianDay :: GDateJulianDay }
        deriving (Eq)
    instance Storable GDate where
        sizeOf _ = 5
    {-# LINE 148 "./System/Glib/GDateTime.chs" #-}
        alignment _ = alignment (undefined :: CString)
        peek =
            (liftM (GDate . fromIntegral)) . g_date_get_julian . castPtr
        poke ptr val =
            g_date_set_julian (castPtr ptr) $ gDateJulianDay val

    data GDateWeekday = GDateBadWeekday
                      | GDateMonday
                      | GDateTuesday
                      | GDateWednesday
                      | GDateThursday
                      | GDateFriday
                      | GDateSaturday
                      | GDateSunday
                      deriving (Eq,Ord)
    instance Enum GDateWeekday where
      fromEnum GDateBadWeekday = 0
      fromEnum GDateMonday = 1
      fromEnum GDateTuesday = 2
      fromEnum GDateWednesday = 3
      fromEnum GDateThursday = 4
      fromEnum GDateFriday = 5
      fromEnum GDateSaturday = 6
      fromEnum GDateSunday = 7

      toEnum 0 = GDateBadWeekday
      toEnum 1 = GDateMonday
      toEnum 2 = GDateTuesday
      toEnum 3 = GDateWednesday
      toEnum 4 = GDateThursday
      toEnum 5 = GDateFriday
      toEnum 6 = GDateSaturday
      toEnum 7 = GDateSunday
      toEnum unmatched = error ("GDateWeekday.toEnum: Cannot match " ++ show unmatched)

      succ GDateBadWeekday = GDateMonday
      succ GDateMonday = GDateTuesday
      succ GDateTuesday = GDateWednesday
      succ GDateWednesday = GDateThursday
      succ GDateThursday = GDateFriday
      succ GDateFriday = GDateSaturday
      succ GDateSaturday = GDateSunday
      succ _ = undefined

      pred GDateMonday = GDateBadWeekday
      pred GDateTuesday = GDateMonday
      pred GDateWednesday = GDateTuesday
      pred GDateThursday = GDateWednesday
      pred GDateFriday = GDateThursday
      pred GDateSaturday = GDateFriday
      pred GDateSunday = GDateSaturday
      pred _ = undefined

      enumFromTo x y | fromEnum x == fromEnum y = [ y ]
                     | otherwise = x : enumFromTo (succ x) y
      enumFrom x = enumFromTo x GDateSunday
      enumFromThen _ _ =     error "Enum GDateWeekday: enumFromThen not implemented"
      enumFromThenTo _ _ _ =     error "Enum GDateWeekday: enumFromThenTo not implemented"

    {-# LINE 155 "./System/Glib/GDateTime.chs" #-}
    instance Bounded GDateWeekday where
        minBound = GDateMonday
        maxBound = GDateSunday

    gDateValidJulian :: GDateJulianDay
                     -> Bool
    gDateValidJulian =
        toBool . g_date_valid_julian
    {-# LINE 163 "./System/Glib/GDateTime.chs" #-}

    gDateValidDMY :: GDateDay
                  -> GDateMonth
                  -> GDateYear
                  -> Bool
    gDateValidDMY (GDateDay day) month (GDateYear year) =
        toBool $ g_date_valid_dmy day
                                                 (fromIntegral $ fromEnum month)
                                                 year

    gDateNewJulian :: GDateJulianDay
                   -> Maybe GDate
    gDateNewJulian julian =
        if gDateValidJulian julian
            then Just $ GDate julian
            else Nothing

    gDateNewDMY :: GDateDay
                -> GDateMonth
                -> GDateYear
                -> Maybe GDate
    gDateNewDMY day month year =
        if gDateValidDMY day month year
            then Just $ unsafePerformIO $ alloca $ \ptr ->
                do let GDateDay day' = day
                       GDateYear year' = year
                   g_date_set_dmy (castPtr ptr)
                                             day'
                                             (fromIntegral $ fromEnum month)
                                             year'
                   peek ptr
            else Nothing

    gDateSetDay :: GDate
                -> GDateDay
                -> Maybe GDate
    gDateSetDay date (GDateDay day) =
        unsafePerformIO $ with date $ \ptr ->
            do g_date_set_day (castPtr ptr) day
               valid <- liftM toBool $ g_date_valid $ castPtr ptr
               if valid
                   then liftM Just $ peek ptr
                   else return Nothing

    gDateSetMonth :: GDate
                  -> GDateMonth
                  -> Maybe GDate
    gDateSetMonth date month =
        unsafePerformIO $ with date $ \ptr ->
            do g_date_set_month (castPtr ptr) $ fromIntegral $ fromEnum month
               valid <- liftM toBool $ g_date_valid $ castPtr ptr
               if valid
                   then liftM Just $ peek ptr
                   else return Nothing

    gDateSetYear :: GDate
                 -> GDateYear
                 -> Maybe GDate
    gDateSetYear :: GDate -> GDateYear -> Maybe GDate
    gDateSetYear GDate
    date (GDateYear CUShort
    year) =
        IO (Maybe GDate) -> Maybe GDate
    forall a. IO a -> a
    unsafePerformIO (IO (Maybe GDate) -> Maybe GDate)
    -> IO (Maybe GDate) -> Maybe GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO (Maybe GDate)) -> IO (Maybe GDate)
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO (Maybe GDate)) -> IO (Maybe GDate))
    -> (Ptr GDate -> IO (Maybe GDate)) -> IO (Maybe GDate)
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do Ptr () -> CUShort -> IO ()
    g_date_set_year (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) CUShort
    year
               Bool
    valid <- (CInt -> Bool) -> IO CInt -> IO Bool
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM CInt -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
    forall a b. (a -> b) -> a -> b
    $ Ptr () -> IO CInt
    g_date_valid (Ptr () -> IO CInt) -> Ptr () -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr
               if Bool
    valid
                   then (GDate -> Maybe GDate) -> IO GDate -> IO (Maybe GDate)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM GDate -> Maybe GDate
    forall a. a -> Maybe a
    Just (IO GDate -> IO (Maybe GDate)) -> IO GDate -> IO (Maybe GDate)
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr
                   else Maybe GDate -> IO (Maybe GDate)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe GDate
    forall a. Maybe a
    Nothing

    gDateNewTimeVal :: GTimeVal
                    -> GDate
    gDateNewTimeVal :: GTimeVal -> GDate
    gDateNewTimeVal GTimeVal
    timeVal =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            GTimeVal -> (Ptr GTimeVal -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GTimeVal
    timeVal ((Ptr GTimeVal -> IO GDate) -> IO GDate)
    -> (Ptr GTimeVal -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GTimeVal
    timeValPtr ->
            do Ptr () -> Ptr () -> IO ()
    g_date_set_time_val (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (Ptr () -> IO ()) -> Ptr () -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Ptr GTimeVal -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GTimeVal
    timeValPtr
               Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateParse :: GlibString string
               => string
               -> IO (Maybe GDate)
    gDateParse :: forall string. GlibString string => string -> IO (Maybe GDate)
    gDateParse string
    str =
        (Ptr GDate -> IO (Maybe GDate)) -> IO (Maybe GDate)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr GDate -> IO (Maybe GDate)) -> IO (Maybe GDate))
    -> (Ptr GDate -> IO (Maybe GDate)) -> IO (Maybe GDate)
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do string -> (CString -> IO ()) -> IO ()
    forall a. string -> (CString -> IO a) -> IO a
    forall s a. GlibString s => s -> (CString -> IO a) -> IO a
    withUTFString string
    str ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Ptr () -> CString -> IO ()
    g_date_set_parse (Ptr () -> CString -> IO ()) -> Ptr () -> CString -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr
               Bool
    valid <- (CInt -> Bool) -> IO CInt -> IO Bool
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM CInt -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
    forall a b. (a -> b) -> a -> b
    $ Ptr () -> IO CInt
    g_date_valid (Ptr () -> IO CInt) -> Ptr () -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr
               if Bool
    valid
                   then (GDate -> Maybe GDate) -> IO GDate -> IO (Maybe GDate)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM GDate -> Maybe GDate
    forall a. a -> Maybe a
    Just (IO GDate -> IO (Maybe GDate)) -> IO GDate -> IO (Maybe GDate)
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr
                   else Maybe GDate -> IO (Maybe GDate)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe GDate
    forall a. Maybe a
    Nothing

    gDateAddDays :: GDate
                 -> Word
                 -> GDate
    gDateAddDays :: GDate -> Word -> GDate
    gDateAddDays GDate
    date Word
    nDays =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do Ptr () -> CUInt -> IO ()
    g_date_add_days (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (CUInt -> IO ()) -> CUInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Word -> CUInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word
    nDays
               Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateSubtractDays :: GDate
                      -> Word
                      -> GDate
    gDateSubtractDays :: GDate -> Word -> GDate
    gDateSubtractDays GDate
    date Word
    nDays =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do Ptr () -> CUInt -> IO ()
    g_date_subtract_days (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (CUInt -> IO ()) -> CUInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Word -> CUInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word
    nDays
               Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateAddMonths :: GDate
                   -> Word
                   -> GDate
    gDateAddMonths :: GDate -> Word -> GDate
    gDateAddMonths GDate
    date Word
    nMonths =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do Ptr () -> CUInt -> IO ()
    g_date_add_months (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (CUInt -> IO ()) -> CUInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Word -> CUInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word
    nMonths
               Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateSubtractMonths :: GDate
                        -> Word
                        -> GDate
    gDateSubtractMonths :: GDate -> Word -> GDate
    gDateSubtractMonths GDate
    date Word
    nMonths =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do Ptr () -> CUInt -> IO ()
    g_date_subtract_months (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (CUInt -> IO ()) -> CUInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Word -> CUInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word
    nMonths
               Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateAddYears :: GDate
                  -> Word
                  -> GDate
    gDateAddYears :: GDate -> Word -> GDate
    gDateAddYears GDate
    date Word
    nYears =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do Ptr () -> CUInt -> IO ()
    g_date_add_years (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (CUInt -> IO ()) -> CUInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Word -> CUInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word
    nYears
               Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateSubtractYears :: GDate
                       -> Word
                       -> GDate
    gDateSubtractYears :: GDate -> Word -> GDate
    gDateSubtractYears GDate
    date Word
    nYears =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            do Ptr () -> CUInt -> IO ()
    g_date_subtract_years (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (CUInt -> IO ()) -> CUInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Word -> CUInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word
    nYears
               Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateDaysBetween :: GDate
                     -> GDate
                     -> Int
    gDateDaysBetween :: GDate -> GDate -> Int
    gDateDaysBetween GDate
    date1 GDate
    date2 =
        CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (CInt -> Int) -> CInt -> Int
    forall a b. (a -> b) -> a -> b
    $ IO CInt -> CInt
    forall a. IO a -> a
    unsafePerformIO (IO CInt -> CInt) -> IO CInt -> CInt
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date1 ((Ptr GDate -> IO CInt) -> IO CInt)
    -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr1 ->
            GDate -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date2 ((Ptr GDate -> IO CInt) -> IO CInt)
    -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr2 ->
                Ptr () -> Ptr () -> IO CInt
    g_date_days_between (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr1) (Ptr () -> IO CInt) -> Ptr () -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr2

    gDateCompare :: GDate
                 -> GDate
                 -> Ordering
    gDateCompare :: GDate -> GDate -> Ordering
    gDateCompare GDate
    date1 GDate
    date2 =
        let result :: Integer
    result = CInt -> Integer
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (CInt -> Integer) -> CInt -> Integer
    forall a b. (a -> b) -> a -> b
    $ IO CInt -> CInt
    forall a. IO a -> a
    unsafePerformIO (IO CInt -> CInt) -> IO CInt -> CInt
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date1 ((Ptr GDate -> IO CInt) -> IO CInt)
    -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr1 ->
                         GDate -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date2 ((Ptr GDate -> IO CInt) -> IO CInt)
    -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr2 ->
                             Ptr () -> Ptr () -> IO CInt
    g_date_compare (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr1) (Ptr () -> IO CInt) -> Ptr () -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr2
            ordering :: Ordering
    ordering | Integer
    result Integer -> Integer -> Bool
    forall a. Ord a => a -> a -> Bool
    < Integer
    0 = Ordering
    LT
                     | Integer
    result Integer -> Integer -> Bool
    forall a. Ord a => a -> a -> Bool
    > Integer
    0 = Ordering
    GT
                     | Bool
    otherwise = Ordering
    EQ
        in Ordering
    ordering

    instance Ord GDate where
        compare :: GDate -> GDate -> Ordering
    compare = GDate -> GDate -> Ordering
    gDateCompare

    gDateClamp :: GDate
               -> GDate
               -> GDate
               -> GDate
    gDateClamp :: GDate -> GDate -> GDate -> GDate
    gDateClamp GDate
    date GDate
    minDate GDate
    maxDate =
        IO GDate -> GDate
    forall a. IO a -> a
    unsafePerformIO (IO GDate -> GDate) -> IO GDate -> GDate
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    ptr ->
            GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    minDate ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    minPtr ->
                GDate -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    maxDate ((Ptr GDate -> IO GDate) -> IO GDate)
    -> (Ptr GDate -> IO GDate) -> IO GDate
    forall a b. (a -> b) -> a -> b
    $ \Ptr GDate
    maxPtr ->
                    do Ptr () -> Ptr () -> Ptr () -> IO ()
    g_date_clamp (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    ptr) (Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    minPtr) (Ptr () -> IO ()) -> Ptr () -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr Ptr GDate
    maxPtr
                       Ptr GDate -> IO GDate
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GDate
    ptr

    gDateDay :: GDate
             -> GDateDay
    gDateDay :: GDate -> GDateDay
    gDateDay GDate
    date =
        CUChar -> GDateDay
    GDateDay (CUChar -> GDateDay) -> CUChar -> GDateDay
    forall a b. (a -> b) -> a -> b
    $ IO CUChar -> CUChar
    forall a. IO a -> a
    unsafePerformIO (IO CUChar -> CUChar) -> IO CUChar -> CUChar
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO CUChar) -> IO CUChar
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO CUChar) -> IO CUChar)
    -> (Ptr GDate -> IO CUChar) -> IO CUChar
    forall a b. (a -> b) -> a -> b
    $ Ptr () -> IO CUChar
    g_date_get_day (Ptr () -> IO CUChar)
    -> (Ptr GDate -> Ptr ()) -> Ptr GDate -> IO CUChar
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr

    gDateMonth :: GDate
               -> GDateMonth
    gDateMonth :: GDate -> GDateMonth
    gDateMonth GDate
    date =
        Int -> GDateMonth
    forall a. Enum a => Int -> a
    toEnum (Int -> GDateMonth) -> Int -> GDateMonth
    forall a b. (a -> b) -> a -> b
    $ CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (CInt -> Int) -> CInt -> Int
    forall a b. (a -> b) -> a -> b
    $ IO CInt -> CInt
    forall a. IO a -> a
    unsafePerformIO (IO CInt -> CInt) -> IO CInt -> CInt
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO CInt) -> IO CInt)
    -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Ptr () -> IO CInt
    g_date_get_month (Ptr () -> IO CInt)
    -> (Ptr GDate -> Ptr ()) -> Ptr GDate -> IO CInt
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr

    gDateYear :: GDate
              -> GDateYear
    gDateYear :: GDate -> GDateYear
    gDateYear GDate
    date =
        CUShort -> GDateYear
    GDateYear (CUShort -> GDateYear) -> CUShort -> GDateYear
    forall a b. (a -> b) -> a -> b
    $ IO CUShort -> CUShort
    forall a. IO a -> a
    unsafePerformIO (IO CUShort -> CUShort) -> IO CUShort -> CUShort
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO CUShort) -> IO CUShort
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO CUShort) -> IO CUShort)
    -> (Ptr GDate -> IO CUShort) -> IO CUShort
    forall a b. (a -> b) -> a -> b
    $ Ptr () -> IO CUShort
    g_date_get_year (Ptr () -> IO CUShort)
    -> (Ptr GDate -> Ptr ()) -> Ptr GDate -> IO CUShort
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr

    gDateWeekday :: GDate
                 -> GDateWeekday
    gDateWeekday :: GDate -> GDateWeekday
    gDateWeekday GDate
    date =
        Int -> GDateWeekday
    forall a. Enum a => Int -> a
    toEnum (Int -> GDateWeekday) -> Int -> GDateWeekday
    forall a b. (a -> b) -> a -> b
    $ CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (CInt -> Int) -> CInt -> Int
    forall a b. (a -> b) -> a -> b
    $ IO CInt -> CInt
    forall a. IO a -> a
    unsafePerformIO (IO CInt -> CInt) -> IO CInt -> CInt
    forall a b. (a -> b) -> a -> b
    $ GDate -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GDate
    date ((Ptr GDate -> IO CInt) -> IO CInt)
    -> (Ptr GDate -> IO CInt) -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Ptr () -> IO CInt
    g_date_get_weekday (Ptr () -> IO CInt)
    -> (Ptr GDate -> Ptr ()) -> Ptr GDate -> IO CInt
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr GDate -> Ptr ()
    forall a b. Ptr a -> Ptr b
    castPtr

    foreign import ccall safe "g_get_current_time"
      g_get_current_time :: ((Ptr ()) -> (IO ()))

    foreign import ccall safe "g_usleep"
      g_usleep :: (CULong -> (IO ()))

    foreign import ccall safe "g_time_val_add"
      g_time_val_add :: ((Ptr ()) -> (CLong -> (IO ())))

    foreign import ccall safe "g_time_val_from_iso8601"
      g_time_val_from_iso8601 :: ((Ptr CChar) -> ((Ptr ()) -> (IO CInt)))

    foreign import ccall safe "g_time_val_to_iso8601"
      g_time_val_to_iso8601 :: ((Ptr ()) -> (IO (Ptr CChar)))

    foreign import ccall safe "g_date_get_julian"
      g_date_get_julian :: ((Ptr ()) -> (IO CUInt))

    foreign import ccall safe "g_date_set_julian"
      g_date_set_julian :: ((Ptr ()) -> (CUInt -> (IO ())))

    foreign import ccall safe "g_date_valid_julian"
      g_date_valid_julian :: (CUInt -> CInt)

    foreign import ccall safe "g_date_valid_dmy"
      g_date_valid_dmy :: (CUChar -> (CInt -> (CUShort -> CInt)))

    foreign import ccall safe "g_date_set_dmy"
      g_date_set_dmy :: ((Ptr ()) -> (CUChar -> (CInt -> (CUShort -> (IO ())))))

    foreign import ccall safe "g_date_set_day"
      g_date_set_day :: ((Ptr ()) -> (CUChar -> (IO ())))

    foreign import ccall safe "g_date_valid"
      g_date_valid :: ((Ptr ()) -> (IO CInt))

    foreign import ccall safe "g_date_set_month"
      g_date_set_month :: ((Ptr ()) -> (CInt -> (IO ())))

    foreign import ccall safe "g_date_set_year"
      g_date_set_year :: ((Ptr ()) -> (CUShort -> (IO ())))

    foreign import ccall safe "g_date_set_time_val"
      g_date_set_time_val :: ((Ptr ()) -> ((Ptr ()) -> (IO ())))

    foreign import ccall safe "g_date_set_parse"
      g_date_set_parse :: ((Ptr ()) -> ((Ptr CChar) -> (IO ())))

    foreign import ccall safe "g_date_add_days"
      g_date_add_days :: ((Ptr ()) -> (CUInt -> (IO ())))

    foreign import ccall safe "g_date_subtract_days"
      g_date_subtract_days :: ((Ptr ()) -> (CUInt -> (IO ())))

    foreign import ccall safe "g_date_add_months"
      g_date_add_months :: ((Ptr ()) -> (CUInt -> (IO ())))

    foreign import ccall safe "g_date_subtract_months"
      g_date_subtract_months :: ((Ptr ()) -> (CUInt -> (IO ())))

    foreign import ccall safe "g_date_add_years"
      g_date_add_years :: ((Ptr ()) -> (CUInt -> (IO ())))

    foreign import ccall safe "g_date_subtract_years"
      g_date_subtract_years :: ((Ptr ()) -> (CUInt -> (IO ())))

    foreign import ccall safe "g_date_days_between"
      g_date_days_between :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))

    foreign import ccall safe "g_date_compare"
      g_date_compare :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))

    foreign import ccall safe "g_date_clamp"
      g_date_clamp :: ((Ptr ()) -> ((Ptr ()) -> ((Ptr ()) -> (IO ()))))

    foreign import ccall safe "g_date_get_day"
      g_date_get_day :: ((Ptr ()) -> (IO CUChar))

    foreign import ccall safe "g_date_get_month"
      g_date_get_month :: ((Ptr ()) -> (IO CInt))

    foreign import ccall safe "g_date_get_year"
      g_date_get_year :: ((Ptr ()) -> (IO CUShort))

    foreign import ccall safe "g_date_get_weekday"
      g_date_get_weekday :: ((Ptr ()) -> (IO CInt))