calenderweek (empty) → 1.0.0
raw patch · 6 files changed
+147/−0 lines, 6 filesdep +basedep +megaparsecdep +optparse-genericsetup-changed
Dependencies added: base, megaparsec, optparse-generic, text, time
Files
- CHANGELOG.md +5/−0
- LICENSE +29/−0
- Main.hs +54/−0
- README.md +28/−0
- Setup.hs +2/−0
- calenderweek.cabal +29/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for calenderweek++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2019, Rolf Meissner+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 the copyright holder nor the names of its+ 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 HOLDER 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.
+ Main.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE OverloadedStrings #-}++module Main where++import Options.Generic+import Data.Maybe+import Data.Time.Calendar+import Data.Time.Calendar.WeekDate (toWeekDate)+import Data.Time.Clock (getCurrentTime, utctDay)+import Text.Megaparsec+import qualified Text.Megaparsec.Char.Lexer as L +import Data.Text+import Data.Void+import Text.Megaparsec.Char+import Control.Monad (void)+++type Parser = Parsec Void Text++data Input = Input (Maybe Text)+ deriving (Generic, Show)++instance ParseRecord Input++weekOfYear :: Day -> Int+weekOfYear = (\(_,b,_) -> b ) . toWeekDate ++parseDay :: Parser Day+parseDay = do+ year <- L.decimal + void (char '-')+ month <- L.decimal + void (char '-')+ day <- L.decimal + return $ fromGregorian year month day++printCurrentWeekofYear :: IO () +printCurrentWeekofYear = do + current <- fmap utctDay getCurrentTime+ putStrLn $ show $ weekOfYear current+ +printWeekofYear datestring = do + let d = parseMaybe parseDay datestring+ case d of+ Nothing -> putStrLn "Error, unable to parse date YYYY-MM-DD"+ Just da -> putStrLn $ show $ weekOfYear da++main = do+ date <- getRecord "kw [YYYY-MM-DD] \n Returns week of year of today or of given date" + case date of+ Nothing -> printCurrentWeekofYear+ Just datestring -> printWeekofYear datestring+
+ README.md view
@@ -0,0 +1,28 @@+# calenderweek++Simple commandline tool to print week of year.+If nothing is provided, the current week is printed.+To query the week of year for a specific date, provide the date in ISO 8601 (YYYY-MM-DD).++## Why++Week of year is often used for communicating a time span. "We are planning to finish the feature in week 50" is a short and precise way to say that we finish between the 9th and the 15th december of 2019. Many Calender programs, like Outlook, are not providing this number. ++## Example +++ kw 2019-11-25+ >48++ kw #week of today+ >48++ kw -h++ >kw [YYYY-MM-DD] Returns week of year of today or of given date+ + >Usage: kw [TEXT]+ + >Available options:+ -h,--help Show this help text+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ calenderweek.cabal view
@@ -0,0 +1,29 @@+cabal-version: >=1.10+name: calenderweek+version: 1.0.0+synopsis: Commandline tool to get week of the year+description: Prints week of year for given date. Installs 'kw' binary that returns week of today or of provided date (YYYY-MM-DD)+bug-reports: https://gitlab.com/rmeis/calenderweek/issues+license: BSD3+license-file: LICENSE+author: Rolf Meissner+maintainer: rolf@msnr.com+copyright: 2019 Rolf Meissner+category: Commandline+build-type: Simple+extra-source-files: CHANGELOG.md, README.md++executable kw+ main-is: Main.hs+ build-depends: base >= 4.12 && < 5.0,+ megaparsec >= 8.0.0 && < 8.1,+ text >= 1.2.3 && < 1.3,+ optparse-generic >= 1.3.0 && < 1.4,+ time >= 1.8.0 && < 1.9.4+ default-language: Haskell2010+++source-repository this+ type: git+ location: https://gitlab.com/rmeis/calenderweek+ tag: 1.0.0