{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Backup.Types.DateRange
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Backup.Types.DateRange where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | This is a resource filter containing FromDate: DateTime and ToDate:
-- DateTime. Both values are required. Future DateTime values are not
-- permitted.
--
-- The date and time are in Unix format and Coordinated Universal Time
-- (UTC), and it is accurate to milliseconds ((milliseconds are optional).
-- For example, the value 1516925490.087 represents Friday, January 26,
-- 2018 12:11:30.087 AM.
--
-- /See:/ 'newDateRange' smart constructor.
data DateRange = DateRange'
  { -- | This value is the beginning date, inclusive.
    --
    -- The date and time are in Unix format and Coordinated Universal Time
    -- (UTC), and it is accurate to milliseconds (milliseconds are optional).
    DateRange -> POSIX
fromDate :: Data.POSIX,
    -- | This value is the end date, inclusive.
    --
    -- The date and time are in Unix format and Coordinated Universal Time
    -- (UTC), and it is accurate to milliseconds (milliseconds are optional).
    DateRange -> POSIX
toDate :: Data.POSIX
  }
  deriving (DateRange -> DateRange -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateRange -> DateRange -> Bool
$c/= :: DateRange -> DateRange -> Bool
== :: DateRange -> DateRange -> Bool
$c== :: DateRange -> DateRange -> Bool
Prelude.Eq, ReadPrec [DateRange]
ReadPrec DateRange
Int -> ReadS DateRange
ReadS [DateRange]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DateRange]
$creadListPrec :: ReadPrec [DateRange]
readPrec :: ReadPrec DateRange
$creadPrec :: ReadPrec DateRange
readList :: ReadS [DateRange]
$creadList :: ReadS [DateRange]
readsPrec :: Int -> ReadS DateRange
$creadsPrec :: Int -> ReadS DateRange
Prelude.Read, Int -> DateRange -> ShowS
[DateRange] -> ShowS
DateRange -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateRange] -> ShowS
$cshowList :: [DateRange] -> ShowS
show :: DateRange -> String
$cshow :: DateRange -> String
showsPrec :: Int -> DateRange -> ShowS
$cshowsPrec :: Int -> DateRange -> ShowS
Prelude.Show, forall x. Rep DateRange x -> DateRange
forall x. DateRange -> Rep DateRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DateRange x -> DateRange
$cfrom :: forall x. DateRange -> Rep DateRange x
Prelude.Generic)

-- |
-- Create a value of 'DateRange' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'fromDate', 'dateRange_fromDate' - This value is the beginning date, inclusive.
--
-- The date and time are in Unix format and Coordinated Universal Time
-- (UTC), and it is accurate to milliseconds (milliseconds are optional).
--
-- 'toDate', 'dateRange_toDate' - This value is the end date, inclusive.
--
-- The date and time are in Unix format and Coordinated Universal Time
-- (UTC), and it is accurate to milliseconds (milliseconds are optional).
newDateRange ::
  -- | 'fromDate'
  Prelude.UTCTime ->
  -- | 'toDate'
  Prelude.UTCTime ->
  DateRange
newDateRange :: UTCTime -> UTCTime -> DateRange
newDateRange UTCTime
pFromDate_ UTCTime
pToDate_ =
  DateRange'
    { $sel:fromDate:DateRange' :: POSIX
fromDate = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pFromDate_,
      $sel:toDate:DateRange' :: POSIX
toDate = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pToDate_
    }

-- | This value is the beginning date, inclusive.
--
-- The date and time are in Unix format and Coordinated Universal Time
-- (UTC), and it is accurate to milliseconds (milliseconds are optional).
dateRange_fromDate :: Lens.Lens' DateRange Prelude.UTCTime
dateRange_fromDate :: Lens' DateRange UTCTime
dateRange_fromDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateRange' {POSIX
fromDate :: POSIX
$sel:fromDate:DateRange' :: DateRange -> POSIX
fromDate} -> POSIX
fromDate) (\s :: DateRange
s@DateRange' {} POSIX
a -> DateRange
s {$sel:fromDate:DateRange' :: POSIX
fromDate = POSIX
a} :: DateRange) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | This value is the end date, inclusive.
--
-- The date and time are in Unix format and Coordinated Universal Time
-- (UTC), and it is accurate to milliseconds (milliseconds are optional).
dateRange_toDate :: Lens.Lens' DateRange Prelude.UTCTime
dateRange_toDate :: Lens' DateRange UTCTime
dateRange_toDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateRange' {POSIX
toDate :: POSIX
$sel:toDate:DateRange' :: DateRange -> POSIX
toDate} -> POSIX
toDate) (\s :: DateRange
s@DateRange' {} POSIX
a -> DateRange
s {$sel:toDate:DateRange' :: POSIX
toDate = POSIX
a} :: DateRange) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

instance Data.FromJSON DateRange where
  parseJSON :: Value -> Parser DateRange
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DateRange"
      ( \Object
x ->
          POSIX -> POSIX -> DateRange
DateRange'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"FromDate")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ToDate")
      )

instance Prelude.Hashable DateRange where
  hashWithSalt :: Int -> DateRange -> Int
hashWithSalt Int
_salt DateRange' {POSIX
toDate :: POSIX
fromDate :: POSIX
$sel:toDate:DateRange' :: DateRange -> POSIX
$sel:fromDate:DateRange' :: DateRange -> POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
fromDate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
toDate

instance Prelude.NFData DateRange where
  rnf :: DateRange -> ()
rnf DateRange' {POSIX
toDate :: POSIX
fromDate :: POSIX
$sel:toDate:DateRange' :: DateRange -> POSIX
$sel:fromDate:DateRange' :: DateRange -> POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf POSIX
fromDate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
toDate

instance Data.ToJSON DateRange where
  toJSON :: DateRange -> Value
toJSON DateRange' {POSIX
toDate :: POSIX
fromDate :: POSIX
$sel:toDate:DateRange' :: DateRange -> POSIX
$sel:fromDate:DateRange' :: DateRange -> POSIX
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"FromDate" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= POSIX
fromDate),
            forall a. a -> Maybe a
Prelude.Just (Key
"ToDate" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= POSIX
toDate)
          ]
      )