Quiq/Time/RFC822.pm

filter: Statementstmt 73.1% 30 / 41 Branchbran 60.0% 12 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 71.2% 52 / 73 CC 12 SCAR 27.8
CC
12
Cov
69%
get
22.4
BEGIN
1.0
BEGIN
1.0
CRAP 16.1
« Quiq/Html/Widget/RadioButtonBar.pm ↑ Summary Quiq/Gd/Component/ColorBar.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Time::RFC822 - Erzeuge Zeitangabe nach RFC 822
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =head1 DESCRIPTION
14  
15 Die von der Klasse generierte Zeitangabe wird für Expires und
16 Set-Cookie HTTP-Header verwendet.
17  
18 =head1 SEE ALSO
19  
20 =over 2
21  
22 =item *
23  
24 Zeitangabe nach RFC 822
25 (L<http://tools.ietf.org/html/rfc822#section-5>)
26  
27 =back
28  
29 =cut
30  
31 # -----------------------------------------------------------------------------
32  
33 package Quiq::Time::RFC822;
34 4 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 4 our $VERSION = '1.240';
41  
42 4 ▶use POSIX qw/:locale_h/;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 # -----------------------------------------------------------------------------
45  
46 =head1 METHODS
47  
48 =head2 Klassenmethoden
49  
50 =head3 get() - Liefere Zeitangabe nach RFC 822
51  
52 =head4 Synopsis
53  
54 $str = $class->get($val);
55  
56 =head4 Description
57  
58 Konvertiere Argument $val in eine Zeitangabe nach RFC 822 und
59 liefere diese zurück.
60  
61 B<Zeitangabe nach RFC 822>
62  
63 Wdy, DD-Mon-YYYY HH:MM:SS GMT
64  
65 B<Arguments>
66  
67 Als Argument $val ist eine Uhrzeit (des heutigen oder morgigen
68 Tages im Format HH:MM), ein bestimmter Zeitpunkt in Unix-Zeit
69 (Sekunden seit 1.1.1970 00:00, GMT), ein Zeitoffset in Sekunden,
70 Minuten, Stunden, Tagen oder Jahren (relativ zum aktuellen Zeitpunkt)
71 oder 'now' und 0 zulässig:
72  
73 N (Unix-Zeit)
74 HH:MM (Zeitpunkt in der Zukunft)
75 +N[ydhms] (Zeit-Offset)
76 now (jetzt)
77 0 (Beginn Unix Epoch)
78  
79 B<Examples>
80  
81 1502795715 (irgendein Zeitpunkt in Unix-Zeit)
82 23:00 (heute 23:00 lokale Zeit, wenn akt. lokale Uhrzeit < 23:00)
83 8:00 (morgen 8:00 lokale Zeit, wenn akt. lokale Uhrzeit >= 8:00)
84 +1y (plus ein Jahr)
85 +7d (plus sieben Tage)
86 +10h (plus zehn Stunden)
87 +30m (plus eine halbe Stunde)
88 +30s (plus 30 Sekunden)
89 now (jetzt)
90 0 (1.1.1970 00:00:00)
91  
92 =cut
93  
94 # -----------------------------------------------------------------------------
95  
96 6 ▶sub get {
Subroutine get: called CC=12 SCAR=31.1
Pod documented
97 6 my ($class,$val) = @_;
98  
99 # aktuelles Zeitformat merken
100 6 my $loc = POSIX::setlocale(POSIX::LC_TIME);
101  
102 # Amerikanisches Zeitformat einstellen
103 6 POSIX::setlocale(POSIX::LC_TIME,'C'); # Fix: CPAN Testers
104  
105 6 my $format = '%a, %d-%b-%Y %H:%M:%S GMT';
106  
107 6 ▶ if (!defined($val) || $val eq 'now') {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $val or $val eq 'now') { } 1 5 6
elsif ($val eq '0') { } 1 4 5
elsif ($val =~ /^(\d+)$/) { } 3 1 4
elsif ($val =~ /^(\d?\d):(\d\d)$/) { } 0 1 1
elsif ($val =~ /^(\+\d+)([smhdy])$/) { } 1 0 1
Condition66%2/3
not defined $val or $val eq "now"
l!l&&r!l&&!r
015
MC/DC50%1/2
not defined $val or $val eq "now"
not defined $val $val eq "now"
Truth table66%2/3
not(A) or B
A= not defined $valB= $val eq "now"
ABresult
1X1
011
000
108 1 $val = POSIX::strftime($format,gmtime);
109 }
110 elsif ($val eq '0') {
111 1 $val = POSIX::strftime($format,gmtime 0);
112 }
113 elsif ($val =~ /^(\d+)$/) {
114 3 $val = POSIX::strftime($format,gmtime $1);
115 }
116 elsif ($val =~ /^(\d?\d):(\d\d)$/) {
117 0 my @time = localtime(CORE::time);
118 0 @time[0 .. 2] = (0,$2,$1);
119 0 my $time = timelocal(@time);
120  
121 # Wenn Zeitlimit innerhalb des Tages erreicht ist,
122 # einen Tag draufaddieren
123 0 ▶ $time += 86400 if $time <= CORE::time;
Branch: 1 branch
BranchTrueFalseTotal
if $time <= time 0 0 0
124  
125 0 $val = POSIX::strftime($format,gmtime($time));
126 }
127 elsif ($val =~ /^(\+\d+)([smhdy])$/) {
128 1 my ($delta,$unit) = ($1,$2);
129  
130 1 ▶ if ($unit eq 'y') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'y') { } 0 1 1
131 0 my(@time) = gmtime(CORE::time);
132 0 $time[5] += $delta;
133  
134 0 $val = POSIX::strftime($format,@time);
135 }
136 else {
137 0 ▶ if ($unit eq 'm') { $delta *= 60 }
Branch: 3 branches
BranchTrueFalseTotal
if ($unit eq 'm') { } 0 1 1
elsif ($unit eq 'h') { } 0 1 1
elsif ($unit eq 'd') { } 0 1 1
138 0 elsif ($unit eq 'h') { $delta *= 3600 }
139 0 elsif ($unit eq 'd') { $delta *= 86400 }
140  
141 1 $val = POSIX::strftime($format,gmtime(CORE::time+$delta));
142 }
143 }
144  
145 # Ursprüngliches Zeitformat wiederherstellen
146 6 POSIX::setlocale(POSIX::LC_TIME,$loc);
147  
148 6 return $val;
149 }
150  
151 # -----------------------------------------------------------------------------
152  
153 =head1 VERSION
154  
155 1.240
156  
157 =head1 AUTHOR
158  
159 Frank Seitz, L<http://fseitz.de/>
160  
161 =head1 COPYRIGHT
162  
163 Copyright (C) 2026 Frank Seitz
164  
165 =head1 LICENSE
166  
167 This code is free software; you can redistribute it and/or modify
168 it under the same terms as Perl itself.
169  
170 =cut
171  
172 # -----------------------------------------------------------------------------
173  
174 4 1;
175  
176 # eof
« Quiq/Html/Widget/RadioButtonBar.pm ↑ Summary Quiq/Gd/Component/ColorBar.pm »