|
1 | | -module Control.Monad.Eff.Now where |
| 1 | +module Control.Monad.Eff.Now |
| 2 | + ( NOW |
| 3 | + , now |
| 4 | + , nowDateTime |
| 5 | + , nowDate |
| 6 | + , nowTime |
| 7 | + , locale |
| 8 | + ) where |
| 9 | + |
| 10 | +import Prelude |
2 | 11 |
|
3 | 12 | import Control.Monad.Eff (Eff) |
4 | | -import Data.DateTime.Instant (Instant) |
| 13 | + |
| 14 | +import Data.DateTime (time, date) |
| 15 | +import Data.DateTime.Instant (Instant, toDateTime) |
| 16 | +import Data.DateTime.Locale (LocalTime, LocalDate, LocalDateTime, LocalValue(..), Locale(..)) |
| 17 | +import Data.Maybe (Maybe(..)) |
| 18 | +import Data.Time.Duration (Minutes) |
5 | 19 |
|
6 | 20 | -- | Effect type for when accessing the current date/time. |
7 | 21 | foreign import data NOW :: ! |
8 | 22 |
|
9 | | --- | Gets an `Instant` value corresponding to the current date/time according to |
10 | | --- | the current machine’s clock. |
| 23 | +-- | Gets an `Instant` value for the date and time according to the current |
| 24 | +-- | machine’s clock. |
11 | 25 | foreign import now :: forall e. Eff (now :: NOW | e) Instant |
| 26 | + |
| 27 | +-- | Gets a `DateTime` value for the date and time according to the current |
| 28 | +-- | machine’s clock. |
| 29 | +nowDateTime :: forall e. Eff (now :: NOW | e) LocalDateTime |
| 30 | +nowDateTime = LocalValue <$> locale <*> (toDateTime <$> now) |
| 31 | + |
| 32 | +-- | Gets the date according to the current machine’s clock. |
| 33 | +nowDate :: forall e. Eff (now :: NOW | e) LocalDate |
| 34 | +nowDate = LocalValue <$> locale <*> (date <<< toDateTime <$> now) |
| 35 | + |
| 36 | +-- | Gets the time according to the current machine’s clock. |
| 37 | +nowTime :: forall e. Eff (now :: NOW | e) LocalTime |
| 38 | +nowTime = LocalValue <$> locale <*> (time <<< toDateTime <$> now) |
| 39 | + |
| 40 | +-- | Gets the locale according to the current machine’s clock. |
| 41 | +-- | |
| 42 | +-- | **Note**: The `LocaleName` will always be empty for the `Locale` value |
| 43 | +-- | returned here until there is a reliable way to detect a name for the |
| 44 | +-- | locale. |
| 45 | +locale :: forall e. Eff (now :: NOW | e) Locale |
| 46 | +locale = Locale Nothing <$> nowOffset |
| 47 | + |
| 48 | +foreign import nowOffset :: forall e. Eff (now :: NOW | e) Minutes |
0 commit comments