public
Description: My personal script stash
Homepage: http://github.com/melo/scripts
Clone URL: git://github.com/melo/scripts.git
Search Repo:
try to parse with the optional modules before using the hard-coded 
patterns

The exception is the match for a single integer number, which we want to 
match epochs.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
melo (author)
Sat May 03 03:52:01 -0700 2008
commit  e322bd568508eda227d5a56cb9a500a187a424e1
tree    bb041eecce357cab28aeabe884f048006c8db0fd
parent  d7e1261d9b05a79c8b221dafd1aa6dff200999bd
...
32
33
34
 
 
 
35
36
37
...
73
74
75
76
77
78
79
80
81
82
83
84
85
...
91
92
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
95
96
...
32
33
34
35
36
37
38
39
40
...
76
77
78
 
 
 
 
 
 
 
79
80
81
...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
0
@@ -32,6 +32,9 @@
0
   if ($t =~ /^\d+$/) {
0
     $dt = DateTime->from_epoch( epoch => $t );
0
   }
0
+ elsif ($dt = try_helper_parsers($t)) {
0
+ # we are done
0
+ }
0
   elsif ($t =~ /^(\d\d\d\d)[-\/](\d+)[-\/](\d+)$/) {
0
     $dt = DateTime->new(
0
         year => $1,
0
@@ -73,13 +76,6 @@
0
         second => $3,
0
     );
0
   }
0
- else {
0
- foreach my $helper (@available) {
0
- next unless $helper->{can_parse};
0
- eval { $dt = $helper->{class}->parse_datetime($t) };
0
- last if $dt;
0
- }
0
- }
0
 
0
   if ($dt) {
0
     print " $t -- $dt ", $dt->epoch, " (hex ", sprintf('%0.4x', $dt->epoch) ,")\n";
0
@@ -91,6 +87,23 @@
0
   else {
0
     print " $t -- could not parse this\n"
0
   }
0
+}
0
+
0
+
0
+####################################################
0
+# Try the helper classes to parse the datetime given
0
+
0
+sub try_helper_parsers {
0
+ my $t = shift;
0
+ my $dt;
0
+
0
+ foreach my $helper (@available) {
0
+ next unless $helper->{can_parse};
0
+ eval { $dt = $helper->{class}->parse_datetime($t) };
0
+ last if $dt;
0
+ }
0
+
0
+ return $dt;
0
 }
0
 
0
 

Comments

    No one has commented yet.