HaskerDeux

Check-in [386fcc875a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Handle any case of short day: Mon, mon, MON, etc.

Just because it'll be easier for me to use lowercase.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/issue1 | trunk | master
Files: files | file ages | folders
SHA3-256: 386fcc875a9b16b4bc6fea7383b3a55e04833cf75bcf14fd7da44e0004e15524
User & Date: atomicules 2020-05-15 08:29:28
Context
2020-05-15
11:56
Hlint changes

Had to hlint on another computer... cannot get it to install on NetBSD check-in: 9a429ebc79 user: atomicules tags: master, origin/issue1, trunk

08:29
Handle any case of short day: Mon, mon, MON, etc.

Just because it'll be easier for me to use lowercase. check-in: 386fcc875a user: atomicules tags: master, origin/issue1, trunk

2020-05-14
20:47
Support using "Mon", "Tue", etc aswell as "today", "tomorrow"

Works well, but not having hlint means my code is messy. Could do with a
further commit that means I can use lower case. And probably lots of tidying
up. check-in: beb9ee5fca user: atomicules tags: master, origin/issue1, trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to haskerdeux.hs.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
{-# LANGUAGE DeriveDataTypeable #-}
--HaskerDeux

import System.Environment
import System.IO
import System.IO.Error
import System.Process

import Data.List
import Data.List.Split --need to install
import Data.Map
import Control.Monad
import Control.Applicative
import Data.Maybe
import Text.JSON --need to install for JSON







>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{-# LANGUAGE DeriveDataTypeable #-}
--HaskerDeux

import System.Environment
import System.IO
import System.IO.Error
import System.Process
import Data.Char
import Data.List
import Data.List.Split --need to install
import Data.Map
import Control.Monad
import Control.Applicative
import Data.Maybe
import Text.JSON --need to install for JSON
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
main = do 
	(date:command:argList) <- getArgs
	time <- getClockTime >>= toCalendarTime --https://wiki.haskell.org/Unix_tools/Date
	let todays_date = formatCalendarTime defaultTimeLocale "%Y-%m-%d" time
	let tomorrows_date = show (addDays 1 $ read todays_date::Data.Time.Day)
	let  todos_date | date == "today" = todays_date
	                | date == "tomorrow" = tomorrows_date
	                | date `elem` ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] = parseday (date, todays_date)
	                | otherwise = date
	when ((command `elem` ["todos"] && Data.List.null argList) || (command `elem` ["new", "crossoff", "putoff", "delete", "nextweek"] && length argList == 1) || (command == "moveto" && length argList == 2)) $ do
		token <- login
		dispatch command (token, todos_date:argList)


parseday (future_day, todays_date) = do
	let days_map = fromList
		[ ("Mon", 0)
		, ("Tue", 1)
		, ("Wed", 2)
		, ("Thu", 3)
		, ("Fri", 4)
		, ("Sat", 5)
		, ("Sun", 6)]
	
	let time_from_string = readTime defaultTimeLocale "%Y-%m-%d" todays_date::Data.Time.Day
	let todays_day = formatTime defaultTimeLocale "%a" time_from_string
	let todays_day_num = fromJust $ Data.Map.lookup todays_day days_map
	let future_day_num = fromJust $ Data.Map.lookup future_day days_map
	let days_to_add | future_day_num >= todays_day_num = future_day_num - todays_day_num
	                | otherwise = (7 + future_day_num) - todays_day_num
	show (addDays days_to_add $ read todays_date::Data.Time.Day)









|








|
|
|
|
|
|
|


|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
main = do 
	(date:command:argList) <- getArgs
	time <- getClockTime >>= toCalendarTime --https://wiki.haskell.org/Unix_tools/Date
	let todays_date = formatCalendarTime defaultTimeLocale "%Y-%m-%d" time
	let tomorrows_date = show (addDays 1 $ read todays_date::Data.Time.Day)
	let  todos_date | date == "today" = todays_date
	                | date == "tomorrow" = tomorrows_date
	                | (Data.List.map toLower date) `elem` ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] = parseday ((Data.List.map toLower date), todays_date)
	                | otherwise = date
	when ((command `elem` ["todos"] && Data.List.null argList) || (command `elem` ["new", "crossoff", "putoff", "delete", "nextweek"] && length argList == 1) || (command == "moveto" && length argList == 2)) $ do
		token <- login
		dispatch command (token, todos_date:argList)


parseday (future_day, todays_date) = do
	let days_map = fromList
		[ ("mon", 0)
		, ("tue", 1)
		, ("wed", 2)
		, ("thu", 3)
		, ("fri", 4)
		, ("sat", 5)
		, ("sun", 6)]
	
	let time_from_string = readTime defaultTimeLocale "%Y-%m-%d" todays_date::Data.Time.Day
	let todays_day = Data.List.map toLower $ formatTime defaultTimeLocale "%a" time_from_string
	let todays_day_num = fromJust $ Data.Map.lookup todays_day days_map
	let future_day_num = fromJust $ Data.Map.lookup future_day days_map
	let days_to_add | future_day_num >= todays_day_num = future_day_num - todays_day_num
	                | otherwise = (7 + future_day_num) - todays_day_num
	show (addDays days_to_add $ read todays_date::Data.Time.Day)