humanisaton of Time output, TODO updated

This commit is contained in:
Yann Esposito 2009-06-12 15:46:33 +02:00
parent 3954287926
commit cb430a15ac
4 changed files with 46 additions and 24 deletions

9
TODO
View file

@ -2,3 +2,12 @@
[2] Code the filter command created:"Thu Jun 11 16:07:59 +0200 2009" [2] Code the filter command created:"Thu Jun 11 16:07:59 +0200 2009"
[3] Code the automatic sort command (it appear to be a complex function) created:"Thu Jun 11 16:08:27 +0200 2009" [3] Code the automatic sort command (it appear to be a complex function) created:"Thu Jun 11 16:08:27 +0200 2009"
[4] Code the modify and extend commands /1\ created:"Thu Jun 11 16:09:24 +0200 2009" [4] Code the modify and extend commands /1\ created:"Thu Jun 11 16:09:24 +0200 2009"
[5] Humanize DateTime output created:"Fri Jun 12 20:00:00 +0200 2009"
[6] Code a Start/Stop task could be multiple tasks in parallel created:"Fri Jun 12 20:00:00 +0200 2009"
[7] Code the standard questionning path for organising tasks created:"Fri Jun 12 20:00:00 +0200 2009"
[8] Code a notification system created:"Fri Jun 12 20:00:00 +0200 2009"
[9] Code the 2 minutes counter created:"Fri Jun 12 20:00:00 +0200 2009"
[10] Code the x5 method (10+2) created:"Fri Jun 12 20:00:00 +0200 2009"
[11] Code nice done task output (from last week, from last day...) created:"Fri Jun 12 20:00:00 +0200 2009"
[12] Code the hability to have repetitives tasks (every week, every month...) created:"Fri Jun 12 20:00:00 +0200 2009"
[13] Recode tag to be able to separate them with commas. created:"Fri Jun 12 20:00:00 +0200 2009"

View file

@ -2,24 +2,28 @@
require 'time' require 'time'
module BetterOutput module HumanTimeOutput
def self.included(base)
base.class_eval do
alias_method :original_to_s, :to_s unless method_defined?(:original_to_s)
# alias_method :to_s, :to_s_humanized
end
end
def is_today? def is_today?
selfTab=self.to_a selfTab=self.to_a
nowTab=Time.now.to_a nowTab=Time.now.to_a
return selfTab[4] == nowTab[4] and return selfTab[4] == nowTab[4] &&
selfTab[5] == nowTab[5] and selfTab[5] == nowTab[5] &&
selfTab[6] == nowTab[6] selfTab[6] == nowTab[6]
end end
def to_s def to_s_humanized
now=Time.now if self.is_today?
nowTab=now.to_a return "today"
selfTab=self.to_a else
self.original_to_s
if (self < now): # in the past end
if is_today?: end
else: # in the future end
end Time.send :include, HumanTimeOutput
end
end
Time.send :include, BetterOutput

View file

@ -4,6 +4,7 @@
require 'rubygems' require 'rubygems'
require 'chronic' require 'chronic'
require 'time' require 'time'
require 'humanTimeOutput.rb'
class TaskTime class TaskTime
@created # creation date of the task @created # creation date of the task

View file

@ -7,10 +7,12 @@ require 'readline'
# #
# it lacks a read config from config file # it lacks a read config from config file
listeEnvVariables=[] listeEnvVariables=[]
autosave=true autosave=true
listeEnvVariables<<='autosave' listeEnvVariables<<='autosave'
defaultTaskFile="TODO"
listeEnvVariables<<='defaultTaskFile' saveFile="TODO"
listeEnvVariables<<='saveFile'
def showVariable (varname) def showVariable (varname)
printf '%20s = ', varname printf '%20s = ', varname
@ -24,8 +26,8 @@ if __FILE__ == $0:
if not autosave: if not autosave:
answer=Readline.readline('Do you want to save your changes? (y/n)',false) answer=Readline.readline('Do you want to save your changes? (y/n)',false)
if not answer =~ /^no?$/: if not answer =~ /^no?$/:
puts "Changes saved in #{defaultTaskFile}" puts "Changes saved in #{saveFile}"
todoList.save defaultTaskFile todoList.save saveFile
end end
end end
puts "\nGood Bye... See you later for another safe and productive day" puts "\nGood Bye... See you later for another safe and productive day"
@ -33,13 +35,13 @@ if __FILE__ == $0:
} }
todoList=TodoList.new todoList=TodoList.new
todoList.load defaultTaskFile todoList.load saveFile
while entry = Readline.readline('> ',true): while entry = Readline.readline('> ',true):
case entry case entry
when /^(a|\+|add) / # ça commence par 'a ' '+ ' ou 'add ' when /^(a|\+|add) / # ça commence par 'a ' '+ ' ou 'add '
todoList.addTask( Task.new(entry.sub(/^(a|\+|add) /,"")) ) todoList.addTask( Task.new(entry.sub(/^(a|\+|add) /,"")) )
if autosave: if autosave:
todoList.save defaultTaskFile todoList.save saveFile
end end
when /^(l|list)( ?(\d*))?/ when /^(l|list)( ?(\d*))?/
if $3.length>0: print "number "+$3 end if $3.length>0: print "number "+$3 end
@ -48,7 +50,7 @@ if __FILE__ == $0:
if $3 and $3.length>0: if $3 and $3.length>0:
filename=$3 filename=$3
else else
filename=defaultTaskFile filename=saveFile
end end
puts "saving to " + filename puts "saving to " + filename
todoList.save filename todoList.save filename
@ -56,7 +58,7 @@ if __FILE__ == $0:
if $2.length>0: if $2.length>0:
filename = $2 filename = $2
else else
filename = defaultTaskFile filename = saveFile
end end
todoList.load filename todoList.load filename
when /^h(elp)?$/ when /^h(elp)?$/
@ -107,11 +109,17 @@ Date: #due_date, #start_date,due_date
eval "puts "+key eval "puts "+key
end end
end end
when /^set ([^= ]*)(=|\s*)(.*)$/
# default all variable are strings
begin
eval $1+"="+$3
end
when /^q(uit)?$/ when /^q(uit)?$/
break break
when /^(!|cmd )(.+)$/ when /^(!|cmd )(.+)$/
system( $2 ) system( $2 )
# must be the last two entries # must be the last two entries
when /^$/
when /^.{1,10}$/ when /^.{1,10}$/
# if the entry is not # if the entry is not
# recognized and less than 10 characters # recognized and less than 10 characters
@ -122,7 +130,7 @@ Date: #due_date, #start_date,due_date
# and not recognized then it is a new entry # and not recognized then it is a new entry
todoList.addTask( Task.new(entry) ) todoList.addTask( Task.new(entry) )
if autosave: if autosave:
todoList.save defaultTaskFile todoList.save saveFile
end end
end end
end end