2009-05-18 09:55:14 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2009-06-02 15:43:28 +00:00
|
|
|
# -- pour la lecture de la date à partir du language naturel
|
|
|
|
require 'rubygems'
|
|
|
|
require 'chronic'
|
2009-06-05 13:59:33 +00:00
|
|
|
require 'time'
|
2009-06-12 13:46:33 +00:00
|
|
|
require 'humanTimeOutput.rb'
|
2009-06-02 15:43:28 +00:00
|
|
|
|
2009-05-18 09:55:14 +00:00
|
|
|
class TaskTime
|
2009-06-08 10:16:29 +00:00
|
|
|
@created # creation date of the task
|
|
|
|
@started # date at with the task began (hour,minute,second)
|
|
|
|
@done # date at which the task was done
|
|
|
|
@due # due date for the task
|
2009-05-18 09:55:14 +00:00
|
|
|
@duration # time spend for finish that task
|
|
|
|
# can be set by the user to be
|
2009-06-08 10:16:29 +00:00
|
|
|
# different than (@done - @started)
|
2009-05-18 09:55:14 +00:00
|
|
|
@max_duration # maximal duration for that task
|
|
|
|
@min_duration # minimal duration for that task
|
2009-06-02 15:43:28 +00:00
|
|
|
|
|
|
|
# -- Expressions regulières --
|
|
|
|
# Regular Expressions for that class
|
2009-06-03 10:19:42 +00:00
|
|
|
@@StdTokenRegExp=Regexp.new(%{(\\w+|"[^"]*")})
|
2009-06-02 15:43:28 +00:00
|
|
|
# Notes
|
2009-06-05 13:59:33 +00:00
|
|
|
@@TimeShort=Regexp.new(%{#(#{@@StdTokenRegExp.inspect[1..-2]}(,|->))?#{@@StdTokenRegExp.inspect[1..-2]}})
|
2009-06-08 10:16:29 +00:00
|
|
|
@@TimeVerbose=Regexp.new(%{ (created|done|due|duration|max_duration|min_duration):#{@@StdTokenRegExp.inspect[1..-2]}} )
|
2009-06-05 13:59:33 +00:00
|
|
|
@@Time=Regexp.union(@@TimeShort,@@TimeVerbose)
|
2009-06-02 15:43:28 +00:00
|
|
|
|
|
|
|
def to_s
|
2009-06-08 10:16:29 +00:00
|
|
|
res=%{created:"#{@created}"}
|
|
|
|
if ( @started ) : res<<=%{,started:"#{@started}"} end
|
|
|
|
if ( @done ) : res<<=%{,done:"#{@done}"} end
|
|
|
|
if ( @due ) : res<<=%{,due:"#{@due}"} end
|
|
|
|
if ( @duration ) : res<<=%{,duration:"#{@duration}"} end
|
|
|
|
if ( @max_duration ): res<<=%{,max_duration:"#{@duration}"} end
|
|
|
|
if ( @min_duration ): res<<=%{,min_duration:"#{@duration}"} end
|
2009-06-02 15:43:28 +00:00
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2009-06-03 10:19:42 +00:00
|
|
|
def to_detailled_s
|
2009-06-08 10:16:29 +00:00
|
|
|
res=%{ created:#{@created}}
|
|
|
|
if ( @started ) : res<<="\n"+%{ started: #{@started}} end
|
|
|
|
if ( @done ) : res<<="\n"+%{ done: #{@done}} end
|
|
|
|
if ( @due ) : res<<="\n"+%{ due: #{@due}} end
|
|
|
|
if ( @duration ) : res<<="\n"+%{ duration: #{@duration}} end
|
|
|
|
if ( @max_duration ): res<<="\n"+%{max_duration: #{@duration}} end
|
|
|
|
if ( @min_duration ): res<<="\n"+%{min_duration: #{@duration}} end
|
2009-06-03 10:19:42 +00:00
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2009-06-02 15:43:28 +00:00
|
|
|
def from_s( raw_input )
|
2009-06-05 13:59:33 +00:00
|
|
|
scanned_input=raw_input.scan( @@TimeShort )
|
2009-06-03 10:19:42 +00:00
|
|
|
str_of_start_date = scanned_input.map{ |x| x[3] }
|
2009-06-08 10:16:29 +00:00
|
|
|
@due = Chronic.parse(str_of_start_date)
|
|
|
|
str_of_due = scanned_input.map{ |x| x[1] }
|
|
|
|
@started = Chronic.parse(str_of_due)
|
2009-06-05 13:59:33 +00:00
|
|
|
raw_input.scan( @@TimeVerbose ).each do |x|
|
2009-06-05 14:36:55 +00:00
|
|
|
timeValue=Chronic.parse(x[1])
|
2009-06-08 10:16:29 +00:00
|
|
|
if timeValue==nil:
|
2009-06-05 14:36:55 +00:00
|
|
|
timeValue=Time.parse(x[1])
|
2009-06-05 13:59:33 +00:00
|
|
|
end
|
|
|
|
eval %{@#{x[0]}=timeValue}
|
|
|
|
end
|
|
|
|
|
2009-06-02 15:43:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize ( raw_input=nil )
|
2009-06-08 10:16:29 +00:00
|
|
|
@created=Time.now
|
|
|
|
@started = nil
|
|
|
|
@done = nil
|
|
|
|
@due = nil
|
2009-06-02 15:43:28 +00:00
|
|
|
@duration = nil
|
|
|
|
@max_duration = nil
|
|
|
|
@min_duration = nil
|
|
|
|
if raw_input:
|
|
|
|
from_s raw_input
|
|
|
|
end
|
2009-05-18 09:55:14 +00:00
|
|
|
end
|
2009-06-02 15:43:28 +00:00
|
|
|
|
|
|
|
def regexp
|
|
|
|
return @@Time
|
2009-05-22 14:45:53 +00:00
|
|
|
end
|
2009-05-18 09:55:14 +00:00
|
|
|
end
|