packages feed

vformat-time (empty) → 0.1.0.0

raw patch · 7 files changed

+209/−0 lines, 7 filesdep +basedep +timedep +vformatsetup-changed

Dependencies added: base, time, vformat, vformat-time

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for vformat-time++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2020 Version Cloud++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Jorah Gao nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# vformat-time++Please see http://hackage.haskell.org/package/vformat-time
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Text/Format/Time.hs view
@@ -0,0 +1,66 @@+{-| This module extend vformat to 'FormatTime' datatypes++The specs of 'FormatTime' is same as the second argument of+"Data.Time.Format.formatTime".++=== Examples++>>> utc <- getCurrentTime+>>> zoned <- getZonedTime+>>> let locale = utcToLocalTime (zonedTimeZone zoned) utc+>>> format "{} / {} / {}" utc zoned locale+"2020-01-21 05:54:41.137832 / 2020-01-21 13:54:45.310354 CST / 2020-01-21 13:54:41.137832"+>>> format "{:%Y-%m-%dT%H:%M:%S}" utc+"2020-01-21T05:54:41"+-}+module Text.Format.Time+  ( formatTimeLocale+  , formatTime+    ) where++import           Data.Time.Calendar+import           Data.Time.Clock+import           Data.Time.Format    hiding (formatTime)+import qualified Data.Time.Format    as T+import           Data.Time.LocalTime+import           Text.Format+++-- | Default specs is @%F@+instance FormatArg Day where+  formatArg = defaultSpecs "%F" formatTime++-- | Default specs is @%F %T%Q@+instance FormatArg UTCTime where+  formatArg = formatTime++-- | Default specs is @%F %T%Q@+instance FormatArg UniversalTime where+  formatArg = formatTime++-- | Default specs is @%Z@+instance FormatArg TimeZone where+  formatArg = defaultSpecs "%Z" formatTime++-- | Default specs is @%T@+instance FormatArg TimeOfDay where+  formatArg = defaultSpecs "%T" formatTime++-- | Default specs is @%F %T%Q@+instance FormatArg LocalTime where+  formatArg = formatTime++-- | Default specs is @%F %T%Q %Z@+instance FormatArg ZonedTime where+  formatArg = defaultSpecs "%F %T%Q %Z" formatTime+++{-| Formatter for 'FormatTime' values using a specific 'TimeLocale'. -}+formatTimeLocale :: FormatTime t => TimeLocale -> t -> Formatter+formatTimeLocale locale = defaultSpecs "%F %T%Q" $ \x k fmt ->+  formatString (T.formatTime locale (fmtSpecs fmt) x) k (fmt{fmtSpecs=""})+++{-| Formatter for 'FormatTime' values using the 'defaultTimeLocale'. -}+formatTime :: FormatTime t => t -> Formatter+formatTime = formatTimeLocale defaultTimeLocale
+ test/Main.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE OverloadedStrings #-}++module Main ( main ) where++import           Control.Exception++import           Data.Time.Calendar+import           Data.Time.Clock+import           Data.Time.Format+import           Data.Time.LocalTime+import           Text.Format+import           Text.Format.Time    hiding (formatTime)++main :: IO ()+main = do+  utc <- getCurrentTime+  zoned <- getZonedTime+  let tz = zonedTimeZone zoned+      locale = utcToLocalTime tz utc+      universal = read (show locale) :: UniversalTime+      day = localDay locale+      time = localTimeOfDay locale++  putStrLn "\n<<<<<<<<<<<<<<<<<<<<<< Test <<<<<<<<<<<<<<<<<<<<<<"++  it "UTCTime default specs" $+    format "{}" utc == formatTimeDef "%F %T%Q" utc+  it "ZonedTime default specs" $+    format "{}" zoned == formatTimeDef "%F %T%Q %Z" zoned+  it "LocalTime default specs" $+    format "{}" locale == formatTimeDef "%F %T%Q" locale+  it "UniversalTime default specs" $+    format "{}" universal == formatTimeDef "%F %T%Q" universal+  it "Day default specs" $+    format "{}" day == formatTimeDef "%F" day+  it "TimeZone default specs" $+    format "{}" tz == formatTimeDef "%Z" tz+  it "Customize specs" $+    format "{:%Y-%m-%d}" utc == formatTimeDef "%Y-%m-%d" utc++  putStrLn "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+++it :: String -> Bool -> IO ()+it = flip assert . putStrLn+++formatTimeDef :: FormatTime t => String -> t -> String+formatTimeDef = formatTime defaultTimeLocale
+ vformat-time.cabal view
@@ -0,0 +1,56 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.1.+--+-- see: https://github.com/sol/hpack+--+-- hash: 6b8cc46edeff772798f6c1f42bf0f2d5b6365fb37b939d2bebe7c5b9c3233b38++name:           vformat-time+version:        0.1.0.0+synopsis:       Extend vformat to time datatypes+description:    Please see http://hackage.haskell.org/package/vformat-time+category:       Text, Format, Time+homepage:       https://github.com/versioncloud/vformat-time#readme+bug-reports:    https://github.com/versioncloud/vformat-time/issues+author:         Jorah Gao+maintainer:     jorah@version.cloud+copyright:      Copyright (c) 2020 Version Cloud+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://github.com/versioncloud/vformat-time++library+  exposed-modules:+      Text.Format.Time+  other-modules:+      Paths_vformat_time+  hs-source-dirs:+      src+  build-depends:+      base >=4.7 && <5+    , time >=1.4 && <2.0+    , vformat >=0.12 && <1.0+  default-language: Haskell2010++test-suite vformat-time-test+  type: exitcode-stdio-1.0+  main-is: Main.hs+  other-modules:+      Paths_vformat_time+  hs-source-dirs:+      test+  ghc-options: -threaded -rtsopts -with-rtsopts=-N -O0+  build-depends:+      base >=4.7 && <5+    , time >=1.4 && <2.0+    , vformat >=0.12 && <1.0+    , vformat-time+  default-language: Haskell2010