-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdate_finder.rb
52 lines (46 loc) · 1.53 KB
/
date_finder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'rubygems'
require 'activesupport'
WorkPeriodStruct = Struct.new(:start,:end,:user,:task,:comment)
relative_path = "./output/"
parsed_data = []
date_strings = []
dates = []
Dir.new(relative_path).each do |fname|
next if fname =~ /^\..*/ #== "." or fname == ".."
print "Processing file '"+fname+"'..\n"
initials = fname.split('-')[0].strip
print "File is for user: '" + initials + "'\n"
File.new(relative_path+fname).each_line do |line|
parts = line.split(',')
#skip lines until we find [date, "WEEK COMMENCING - ", ...]
next unless parts[0]
matchdata = parts[0].match(/"WEEK COMMENCING/)
d = nil
if matchdata
date_strings << parts
if parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d)"/)
mdata = parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d)"/)
d = Date.strptime(mdata[1], '%d.%m.%y')
elsif parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d\d\d)"/)
mdata = parts[0].match(/"WEEK COMMENCING - (\d\d.\d\d.\d\d\d\d)"/)
d = Date.strptime(mdata[1], '%d.%m.%Y')
elsif parts[2].match(/(\d\d\d\d-\d\d-\d\d)/)
mdata = parts[2].match(/(\d\d\d\d-\d\d-\d\d)/)
d = Date.strptime(mdata[1], '%Y-%m-%d')
else
p line
raise "Bad date!"
end
if d.wday != 1
print "did not have a monday: " + d.to_s + " (wday is " + d.wday.to_s + ")\n"
end
dates << d
end
end
end
dates.uniq!.sort!
p dates[0]
p dates.last
date_strings.uniq.each do |x|
p x
end