diff options
Diffstat (limited to 'rhimport.pm')
-rw-r--r-- | rhimport.pm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/rhimport.pm b/rhimport.pm index 79c921e..6181f56 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -30,6 +30,9 @@ use IPC::Open3; use File::Spec; use File::Basename; use URI::Escape; +use POSIX; +use DateTime; +use DateTime::TimeZone; my $ssh_host = "airplay"; my $ssh_user = "rhimport"; @@ -37,6 +40,33 @@ my $ssh_key_file = "$ENV{'HOME'}/.rhimport/import.key"; my $ssh_dir = "/programm/.rhimport"; my $rdimport_wrapper = "/usr/local/bin/dropbox_newfile.pl"; +sub get_rd_week +{ + # + # This computes the current Rivendell Week based on the number + # of weeks since epoch. + # + # Explanation: + # epoch was at 01.01.1970 which was a Thursday. + # Monday in that week is (s-from-epoch + 3*24*60*60) seconds ago. + # This needs to be adjusted by the timezone offset for Europe/Vienna + # which is of course not constant (damn you daylight savings time) + # Divide this by (7*24*60*60) and you get the number of + # weeks since the Monday in the week of epoch adjusted for timezone offsets. + # This week had week number 3 so add an offset of 2 and + # get the modulo of 4. This rounded down gives you the current week + # with 0 meaning Week 1. So add 1 to that number and you will get + # the current RD week. + # + my $now = DateTime->now(); + my $tz = DateTime::TimeZone->new(name => 'Europe/Vienna'); + my $tz_offset = $tz->offset_for_datetime($now); + my $sEpoch = $now->epoch() + $tz_offset; + my $week = floor(((($sEpoch + 259200)/604800) + 2) % 4) + 1; + + return $week; +} + sub check_key_file { if(-e "$ssh_key_file") { |