summaryrefslogtreecommitdiff
path: root/rhimport.pm
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-10 16:36:41 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-10 16:36:41 (GMT)
commitc5bda0a596d9f8c6e1b3767c1091b3e403ff99c8 (patch)
tree9e529bcf1102a1652ff842422962634813affe8c /rhimport.pm
parentcaab0e9dcb749512581405c42e516107f9c0ef25 (diff)
replaced fetching of current week by static calculation algorightm
Diffstat (limited to 'rhimport.pm')
-rw-r--r--rhimport.pm30
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") {