1 |
joko |
1.1 |
## ------------------------------------------------------------------------ |
2 |
jonen |
1.4 |
## $Id: Merge.pm,v 1.3 2003/02/09 16:15:51 joko Exp $ |
3 |
joko |
1.1 |
## ------------------------------------------------------------------------ |
4 |
joko |
1.2 |
## $Log: Merge.pm,v $ |
5 |
jonen |
1.4 |
## Revision 1.3 2003/02/09 16:15:51 joko |
6 |
|
|
## + minor update regarding module namespace refactoring |
7 |
|
|
## |
8 |
joko |
1.3 |
## Revision 1.2 2002/12/23 13:44:53 joko |
9 |
|
|
## + sub stripDayName |
10 |
|
|
## |
11 |
joko |
1.2 |
## Revision 1.1 2002/12/22 14:15:59 joko |
12 |
|
|
## + initial check-in |
13 |
|
|
## |
14 |
joko |
1.1 |
## ------------------------------------------------------------------------ |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
package Date::Merge; |
18 |
|
|
|
19 |
|
|
use strict; |
20 |
|
|
use warnings; |
21 |
|
|
|
22 |
|
|
require Exporter; |
23 |
|
|
our @ISA = qw( Exporter ); |
24 |
|
|
our @EXPORT_OK = qw( |
25 |
|
|
mergeDayAndTime |
26 |
joko |
1.2 |
stripDayName |
27 |
joko |
1.1 |
); |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
use Date::Manip; |
31 |
joko |
1.3 |
use shortcuts qw( today ); |
32 |
joko |
1.1 |
|
33 |
|
|
|
34 |
|
|
sub mergeDayAndTime { |
35 |
|
|
|
36 |
|
|
my $day = shift; |
37 |
|
|
my $time = shift; |
38 |
|
|
|
39 |
|
|
my $date_day_raw = $day; |
40 |
|
|
my $date_time_raw = $time; |
41 |
|
|
|
42 |
|
|
# TODO: abstract this out (to a helper function) somehow |
43 |
|
|
# take care not to exclude/export/refactor _this_ type of helper function to nirvana |
44 |
|
|
# remember just _everything_ out of this scope is nirvana, so - right said - take care to stay in scope ... |
45 |
|
|
# ... else this compartment would theoretically break, but may still work in real use under some "easy" circumstances |
46 |
|
|
# (e.g. no other containerships, no parallelity, anything may/might happen) |
47 |
|
|
# REVIEW: what about re-entrancy of _this_ type of helper functions/methods? |
48 |
|
|
|
49 |
|
|
$date_day_raw =~ s/[^\d|-]//g; |
50 |
|
|
my $date_day = ParseDate($date_day_raw); |
51 |
jonen |
1.4 |
|
52 |
joko |
1.1 |
# $date_time (just the time!) will get auto-converted to a datetime from today, so .... |
53 |
|
|
my $date_time = ParseDate($date_time_raw); |
54 |
|
|
|
55 |
|
|
# ... we should calculate the delta to get the real time-shift to continue further processing with |
56 |
jonen |
1.4 |
#my $date_time_delta = DateCalc(ParseDate(today()), '-' . $date_time); |
57 |
|
|
my $date_time_delta = DateCalc(ParseDate(today()), $date_time); |
58 |
joko |
1.1 |
|
59 |
|
|
# add the delta to the 'date-day' parsed above to calculate the complete event-date ('endtime' in this case) |
60 |
|
|
my $date_complete = DateCalc($date_day, $date_time_delta); |
61 |
|
|
|
62 |
|
|
# reformat the complete date to be a full compliant database-date |
63 |
|
|
my $date_full = UnixDate($date_complete, '%Y-%m-%d %H:%M:%S'); |
64 |
|
|
|
65 |
|
|
return $date_full; |
66 |
|
|
|
67 |
joko |
1.2 |
} |
68 |
|
|
|
69 |
|
|
sub stripDayName { |
70 |
|
|
|
71 |
|
|
my $date_raw = shift; |
72 |
|
|
$date_raw =~ s/[^\d|-]//g; |
73 |
|
|
|
74 |
|
|
my $date_parsed = ParseDate($date_raw); |
75 |
|
|
|
76 |
|
|
my $date_full = UnixDate($date_parsed, '%Y-%m-%d %H:%M:%S'); |
77 |
|
|
|
78 |
|
|
return $date_full; |
79 |
|
|
|
80 |
joko |
1.1 |
} |
81 |
|
|
|
82 |
|
|
1; |