std sh ga-infounused
[sunny256-utils.git] / sommer
blobfada2600cc6f22779d3cf6552dcda9a8dafa2693
1 #!/usr/bin/env perl
3 # sommer
4 # File ID: 341567e0-5d44-11df-abec-90e6ba3022ac
5 # Syntax: $0 år måned dag time min sek
6 # Finner ut om datoen (norsk tid) er sommertid.
7 # Returnerer 0 hvis vintertid, 1 hvis sommertid.
9 use Time::Local;
11 my ($Year, $Mon, $Day, $Hour, $Min, $Sec) = @ARGV;
13 $Year += 1900 if ($Year < 100); # Heia år 2000
14 my $GM = timegm($Sec, $Min, $Hour, $Day, $Mon-1, $Year);
15 my $LO = timelocal($Sec, $Min, $Hour, $Day, $Mon-1, $Year);
17 my $Diff = ($GM-$LO)/3600;
18 $GM =~ s/(^|\D)(\d{9})(\D|$)/@TA = localtime($2),sprintf("%s%04u-%02u-%02uT%02u:%02u:%02u%s", $1, $TA[5]+1900, $TA[4]+1, $TA[3], $TA[2], $TA[1], $TA[0], $3)/ge;
19 $LO =~ s/(^|\D)(\d{9})(\D|$)/@TA = localtime($2),sprintf("%s%04u-%02u-%02uT%02u:%02u:%02u%s", $1, $TA[5]+1900, $TA[4]+1, $TA[3], $TA[2], $TA[1], $TA[0], $3)/ge;
21 # print "GM = $GM\n";
22 # print "LO = $LO\n";
23 # print "\n";
25 my $Sommer = ($Diff == 2) ? 1 : 0;
27 printf("%04u-%02u-%02u %02u:%02u:%02u : %stid (GMT+%02u00)\n", $Year, $Mon, $Day, $Hour, $Min, $Sec, $Sommer ? "sommer" : "vinter", $Diff);
29 exit $Sommer;
31 #### End of file sommer ####