📄 manip.pm
字号:
@format=($format); $scalar=1; } # month, week $_=$m; s/^0//; $f{"b"}=$f{"h"}=$Lang{$Cnf{"Language"}}{"MonL"}[$_-1]; $f{"B"}=$Lang{$Cnf{"Language"}}{"MonthL"}[$_-1]; $_=$m; s/^0/ /; $f{"f"}=$_; $f{"U"}=&Date_WeekOfYear($m,$d,$y,7); $f{"W"}=&Date_WeekOfYear($m,$d,$y,1); # check week 52,53 and 0 $f{"G"}=$f{"L"}=$y; if ($f{"W"}>=52 || $f{"U"}>=52) { my($dd,$mm,$yy)=($d,$m,$y); $dd+=7; if ($dd>31) { $dd-=31; $mm=1; $yy++; if (&Date_WeekOfYear($mm,$dd,$yy,1)==2) { $f{"G"}=$yy; $f{"W"}=1; } if (&Date_WeekOfYear($mm,$dd,$yy,7)==2) { $f{"L"}=$yy; $f{"U"}=1; } } } if ($f{"W"}==0) { my($dd,$mm,$yy)=($d,$m,$y); $dd-=7; $dd+=31 if ($dd<1); $yy--; $mm=12; $f{"G"}=$yy; $f{"W"}=&Date_WeekOfYear($mm,$dd,$yy,1)+1; } if ($f{"U"}==0) { my($dd,$mm,$yy)=($d,$m,$y); $dd-=7; $dd+=31 if ($dd<1); $yy--; $mm=12; $f{"L"}=$yy; $f{"U"}=&Date_WeekOfYear($mm,$dd,$yy,7)+1; } $f{"U"}="0".$f{"U"} if (length $f{"U"} < 2); $f{"W"}="0".$f{"W"} if (length $f{"W"} < 2); # day $f{"j"}=&Date_DayOfYear($m,$d,$y); $f{"j"} = "0" . $f{"j"} while (length($f{"j"})<3); $_=$d; s/^0/ /; $f{"e"}=$_; $f{"w"}=&Date_DayOfWeek($m,$d,$y); $f{"v"}=$Lang{$Cnf{"Language"}}{"WL"}[$f{"w"}-1]; $f{"v"}=" ".$f{"v"} if (length $f{"v"} < 2); $f{"a"}=$Lang{$Cnf{"Language"}}{"WkL"}[$f{"w"}-1]; $f{"A"}=$Lang{$Cnf{"Language"}}{"WeekL"}[$f{"w"}-1]; $f{"E"}=&Date_DaySuffix($f{"e"}); # hour $_=$h; s/^0/ /; $f{"k"}=$_; $f{"i"}=$f{"k"}+1; $f{"i"}=$f{"k"}; $f{"i"}=12 if ($f{"k"}==0); $f{"i"}=$f{"k"}-12 if ($f{"k"}>12); $f{"i"}=$f{"i"}-12 if ($f{"i"}>12); $f{"i"}=" ".$f{"i"} if (length($f{"i"})<2); $f{"I"}=$f{"i"}; $f{"I"}=~ s/^ /0/; $f{"p"}=$Lang{$Cnf{"Language"}}{"AMstr"}; $f{"p"}=$Lang{$Cnf{"Language"}}{"PMstr"} if ($f{"k"}>11); # minute, second, timezone $f{"o"}=&Date_SecsSince1970($m,$d,$y,$h,$mn,$s); $f{"s"}=&Date_SecsSince1970GMT($m,$d,$y,$h,$mn,$s); $f{"Z"}=($Cnf{"ConvTZ"} eq "IGNORE" or $Cnf{"ConvTZ"} eq "") ? $Cnf{"TZ"} : $Cnf{"ConvTZ"}; $f{"z"}=($Zone{"n2o"}{lc $f{"Z"}} || ""); # date, time $f{"c"}=qq|$f{"a"} $f{"b"} $f{"e"} $h:$mn:$s $y|; $f{"C"}=$f{"u"}= qq|$f{"a"} $f{"b"} $f{"e"} $h:$mn:$s $f{"z"} $y|; $f{"g"}=qq|$f{"a"}, $d $f{"b"} $y $h:$mn:$s $f{"z"}|; $f{"D"}=$f{"x"}=qq|$m/$d/$f{"y"}|; $f{"r"}=qq|$f{"I"}:$mn:$s $f{"p"}|; $f{"R"}=qq|$h:$mn|; $f{"T"}=$f{"X"}=qq|$h:$mn:$s|; $f{"V"}=qq|$m$d$h$mn$f{"y"}|; $f{"Q"}="$y$m$d"; $f{"q"}=qq|$y$m$d$h$mn$s|; $f{"P"}=qq|$y$m$d$h:$mn:$s|; $f{"F"}=qq|$f{"A"}, $f{"B"} $f{"e"}, $f{"Y"}|; if ($f{"W"}==0) { $y--; $tmp=&Date_WeekOfYear(12,31,$y,1); $tmp="0$tmp" if (length($tmp) < 2); $f{"J"}=qq|$y-W$tmp-$f{"w"}|; } else { $f{"J"}=qq|$f{"G"}-W$f{"W"}-$f{"w"}|; } $f{"K"}=qq|$y-$f{"j"}|; # %l is a special case. Since it requires the use of the calculator # which requires this routine, an infinite recursion results. To get # around this, %l is NOT determined every time this is called so the # recursion breaks. # other formats $f{"n"}="\n"; $f{"t"}="\t"; $f{"%"}="%"; $f{"+"}="+"; foreach $format (@format) { $format=reverse($format); $out=""; while ($format ne "") { $c=chop($format); if ($c eq "%") { $c=chop($format); if ($c eq "l") { &Date_Init(); $date1=&DateCalc_DateDelta($Curr{"Now"},"-0:6:0:0:0:0:0"); $date2=&DateCalc_DateDelta($Curr{"Now"},"+0:6:0:0:0:0:0"); if (&Date_Cmp($date,$date1)>=0 && &Date_Cmp($date,$date2)<=0) { $f{"l"}=qq|$f{"b"} $f{"e"} $h:$mn|; } else { $f{"l"}=qq|$f{"b"} $f{"e"} $f{"Y"}|; } $out .= $f{"$c"}; } elsif (exists $f{"$c"}) { $out .= $f{"$c"}; } else { $out .= $c; } } else { $out .= $c; } } push(@out,$out); } if ($scalar) { return $out[0]; } else { return (@out); }}# Can't be in "use integer" because we're doing decimal arithmaticno integer;sub Delta_Format { print "DEBUG: Delta_Format\n" if ($Curr{"Debug"} =~ /trace/); my($delta,$dec,@format)=@_; $delta=&ParseDateDelta($delta); return "" if (! $delta); my(@out,%f,$out,$c1,$c2,$scalar,$format)=(); local($_)=$delta; my($y,$M,$w,$d,$h,$m,$s)=&Delta_Split($delta); # Get rid of positive signs. ($y,$M,$w,$d,$h,$m,$s)=map { 1*$_; }($y,$M,$w,$d,$h,$m,$s); if (defined $dec && $dec>0) { $dec="%." . ($dec*1) . "f"; } else { $dec="%f"; } if (! wantarray) { $format=join(" ",@format); @format=($format); $scalar=1; } # Length of each unit in seconds my($sl,$ml,$hl,$dl,$wl)=(); $sl = 1; $ml = $sl*60; $hl = $ml*60; $dl = $hl*24; $wl = $dl*7; # The decimal amount of each unit contained in all smaller units my($yd,$Md,$sd,$md,$hd,$dd,$wd)=(); $yd = $M/12; $Md = 0; $wd = ($d*$dl + $h*$hl + $m*$ml + $s*$sl)/$wl; $dd = ($h*$hl + $m*$ml + $s*$sl)/$dl; $hd = ($m*$ml + $s*$sl)/$hl; $md = ($s*$sl)/$ml; $sd = 0; # The amount of each unit contained in higher units. my($yh,$Mh,$sh,$mh,$hh,$dh,$wh)=(); $yh = 0; $Mh = ($yh+$y)*12; $wh = 0; $dh = ($wh+$w)*7; $hh = ($dh+$d)*24; $mh = ($hh+$h)*60; $sh = ($mh+$m)*60; # Set up the formats $f{"yv"} = $y; $f{"Mv"} = $M; $f{"wv"} = $w; $f{"dv"} = $d; $f{"hv"} = $h; $f{"mv"} = $m; $f{"sv"} = $s; $f{"yh"} = $y+$yh; $f{"Mh"} = $M+$Mh; $f{"wh"} = $w+$wh; $f{"dh"} = $d+$dh; $f{"hh"} = $h+$hh; $f{"mh"} = $m+$mh; $f{"sh"} = $s+$sh; $f{"yd"} = sprintf($dec,$y+$yd); $f{"Md"} = sprintf($dec,$M+$Md); $f{"wd"} = sprintf($dec,$w+$wd); $f{"dd"} = sprintf($dec,$d+$dd); $f{"hd"} = sprintf($dec,$h+$hd); $f{"md"} = sprintf($dec,$m+$md); $f{"sd"} = sprintf($dec,$s+$sd); $f{"yt"} = sprintf($dec,$yh+$y+$yd); $f{"Mt"} = sprintf($dec,$Mh+$M+$Md); $f{"wt"} = sprintf($dec,$wh+$w+$wd); $f{"dt"} = sprintf($dec,$dh+$d+$dd); $f{"ht"} = sprintf($dec,$hh+$h+$hd); $f{"mt"} = sprintf($dec,$mh+$m+$md); $f{"st"} = sprintf($dec,$sh+$s+$sd); $f{"%"} = "%"; foreach $format (@format) { $format=reverse($format); $out=""; PARSE: while ($format) { $c1=chop($format); if ($c1 eq "%") { $c1=chop($format); if (exists($f{$c1})) { $out .= $f{$c1}; next PARSE; } $c2=chop($format); if (exists($f{"$c1$c2"})) { $out .= $f{"$c1$c2"}; next PARSE; } $out .= $c1; $format .= $c2; } else { $out .= $c1; } } push(@out,$out); } if ($scalar) { return $out[0]; } else { return (@out); }}use integer;sub ParseRecur { print "DEBUG: ParseRecur\n" if ($Curr{"Debug"} =~ /trace/); &Date_Init() if (! $Curr{"InitDone"}); my($recur,$dateb,$date0,$date1,$flag)=@_; local($_)=$recur; my($recur_0,$recur_1,@recur0,@recur1)=(); my(@tmp,$tmp,$each,$num,$y,$m,$d,$w,$h,$mn,$s,$delta,$y0,$y1,$yb)=(); my($yy,$n,$dd,@d,@tmp2,$date,@date,@w,@tmp3,@m,@y,$tmp2,$d2,@flags)=(); # $date0, $date1, $dateb, $flag : passed in (these are always the final say # in determining whether a date matches a # recurrence IF they are present. # $date_b, $date_0, $date_1 : if a value can be determined from the # $flag_t recurrence, they are stored here. # # If values can be determined from the recurrence AND are passed in, the # following are used: # max($date0,$date_0) i.e. the later of the two dates # min($date1,$date_1) i.e. the earlier of the two dates # # The base date that is used is the first one defined from # $dateb $date_b # The base date is only used if necessary (as determined by the recur). # For example, "every other friday" requires a base date, but "2nd # friday of every month" doesn't. my($date_b,$date_0,$date_1,$flag_t); # # Check the arguments passed in. # $date0="" if (! defined $date0); $date1="" if (! defined $date1); $dateb="" if (! defined $dateb); $flag ="" if (! defined $flag); if ($dateb) { $dateb=&ParseDateString($dateb); return "" if (! $dateb); } if ($date0) { $date0=&ParseDateString($date0); return "" if (! $date0); } if ($date1) { $date1=&ParseDateString($date1); return "" if (! $date1); } # # Parse the recur. $date_b, $date_0, and $date_e are values obtained # from the recur. # @tmp=&Recur_Split($_); if (@tmp) { ($recur_0,$recur_1,$flag_t,$date_b,$date_0,$date_1)=@tmp; $recur_0 = "" if (! defined $recur_0); $recur_1 = "" if (! defined $recur_1); $flag_t = "" if (! defined $flag_t); $date_b = "" if (! defined $date_b); $date_0 = "" if (! defined $date_0); $date_1 = "" if (! defined $date_1); @recur0 = split(/:/,$recur_0); @recur1 = split(/:/,$recur_1); return "" if ($#recur0 + $#recur1 + 2 != 7); if ($date_b) { $date_b=&ParseDateString($date_b); return "" if (! $date_b); } if ($date_0) { $date_0=&ParseDateString($date_0); return "" if (! $date_0); } if ($date_1) { $date_1=&ParseDateString($date_1); return "" if (! $date_1); } } else { my($mmm)='\s*'.$Lang{$Cnf{"Language"}}{"Month"}; # \s*(jan|january|...) my(%mmm)=%{ $Lang{$Cnf{"Language"}}{"MonthH"} }; # { jan=>1, ... } my($wkexp)='\s*'.$Lang{$Cnf{"Language"}}{"Week"}; # \s*(mon|monday|...) my(%week)=%{ $Lang{$Cnf{"Language"}}{"WeekH"} }; # { monday=>1, ... } my($day)='\s*'.$Lang{$Cnf{"Language"}}{"Dabb"}; # \s*(?:d|day|days) my($month)='\s*'.$Lang{$Cnf{"Language"}}{"Mabb"}; # \s*(?:mon|month|months) my($week)='\s*'.$Lang{$Cnf{"Language"}}{"Wabb"}; # \s*(?:w|wk|week|weeks) my($daysexp)=$Lang{$Cnf{"Language"}}{"DoM"}; # (1st|first|...31st) my(%dayshash)=%{ $Lang{$Cnf{"Language"}}{"DoMH"} }; # { 1st=>1,first=>1,...} my($of)='\s*'.$Lang{$Cnf{"Language"}}{"Of"}; # \s*(?:in|of) my($lastexp)=$Lang{$Cnf{"Language"}}{"Last"}; # (?:last) my($each)=$Lang{$Cnf{"Language"}}{"Each"}; # (?:each|every) my($D)='\s*(\d+)'; my($Y)='\s*(\d{4}|\d{2})'; # Change 1st to 1 if (/(^|[^a-z])$daysexp($|[^a-z])/i) { $tmp=lc($2); $tmp=$dayshash{"$tmp"}; s/(^|[^a-z])$daysexp($|[^a-z])/$1 $tmp $3/i; } s/\s*$//; # Get rid of "each" if (/(^|[^a-z])$each($|[^a-z])/i) { s/(^|[^a-z])$each($|[^a-z])/$1 $2/i; $each=1; } else { $each=0; } if ($each) { if (/^$D?$day(?:$of$mmm?$Y)?$/i || /^$D?$day(?:$of$mmm())?$/i) { # every [2nd] day in [june] 1997 # every [2nd] day [in june] ($num,$m,$y)=($1,$2,$3); $num=1 if (! defined $num); $m="" if (! defined $m); $y="" if (! defined $y); $y=$Curr{"Y"} if (! $y); if ($m) { $m=$mmm{lc($m)}; $date_0=&Date_Join($y,$m,1,0,0,0); $date_1=&DateCalc_DateDelta($date_0,"+0:1:0:0:0:0:0",0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -