line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Time::Duration::sv; |
3
|
|
|
|
|
|
|
# Time-stamp: "2002-10-08 01:04:09 MDT" POD is at the end. |
4
|
|
|
|
|
|
|
$VERSION = '1.01'; |
5
|
|
|
|
|
|
|
require Exporter; |
6
|
|
|
|
|
|
|
@ISA = ('Exporter'); |
7
|
|
|
|
|
|
|
@EXPORT = qw( later later_exact earlier earlier_exact |
8
|
|
|
|
|
|
|
ago ago_exact from_now from_now_exact |
9
|
|
|
|
|
|
|
duration duration_exact |
10
|
|
|
|
|
|
|
concise |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
@EXPORT_OK = ('interval', @EXPORT); |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
8496
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
15
|
1
|
|
|
1
|
|
6
|
use constant DEBUG => 0; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
92
|
|
16
|
1
|
|
|
1
|
|
981
|
use Time::Duration qw(); |
|
1
|
|
|
|
|
2474
|
|
|
1
|
|
|
|
|
962
|
|
17
|
|
|
|
|
|
|
# ALL SUBS ARE PURE FUNCTIONS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub concise ($) { |
22
|
29
|
|
|
29
|
0
|
43
|
my $string = $_[0]; |
23
|
|
|
|
|
|
|
#print "in : $string\n"; |
24
|
29
|
|
|
|
|
64
|
$string =~ s/,//g; |
25
|
29
|
|
|
|
|
62
|
$string =~ s/\boch\b//; |
26
|
29
|
|
|
|
|
132
|
$string =~ s/\b(dag|dagar|timme|timmar|minut|minuter|sekund|sekunder)\b/substr($1,0,1)/eg; |
|
36
|
|
|
|
|
139
|
|
27
|
29
|
|
|
|
|
61
|
$string =~s/år/å/g; |
28
|
29
|
|
|
|
|
36
|
my $save = ''; |
29
|
29
|
100
|
|
|
|
105
|
if($string =~s/(för|om)//) { |
30
|
4
|
|
|
|
|
8
|
$save = $1; |
31
|
|
|
|
|
|
|
} |
32
|
29
|
|
|
|
|
220
|
$string =~ s/\s*(\d+)\s*/$1/g; |
33
|
|
|
|
|
|
|
|
34
|
29
|
100
|
|
|
|
128
|
return $save ? $save . " " . $string : $string; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub later { |
38
|
68
|
|
|
68
|
0
|
4435
|
interval( $_[0], $_[1], '%s tidigare', '%s senare', 'just då'); } |
39
|
|
|
|
|
|
|
sub later_exact { |
40
|
31
|
|
|
31
|
0
|
3177
|
interval_exact($_[0], $_[1], '%s tidigare', '%s senare', 'just då'); } |
41
|
|
|
|
|
|
|
sub earlier { |
42
|
6
|
|
|
6
|
0
|
303
|
interval( $_[0], $_[1], '%s senare', '%s tidigare', 'just då'); } |
43
|
|
|
|
|
|
|
sub earlier_exact { |
44
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], '%s senare', '%s tidigare', 'just då'); } |
45
|
|
|
|
|
|
|
sub ago { |
46
|
6
|
|
|
6
|
0
|
312
|
interval( $_[0], $_[1], 'om %s', 'för %s sen', 'just nu'); } |
47
|
|
|
|
|
|
|
sub ago_exact { |
48
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], 'för %s sen', '%s ago', 'just nu'); } |
49
|
|
|
|
|
|
|
sub from_now { |
50
|
6
|
|
|
6
|
0
|
1648
|
interval( $_[0], $_[1], 'för %s sen', 'om %s', 'just nu'); } |
51
|
|
|
|
|
|
|
sub from_now_exact { |
52
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], 'för %s sen', 'om %s', 'just nu'); } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
55
|
|
|
|
|
|
|
sub duration_exact { |
56
|
2
|
|
|
2
|
0
|
114
|
my $span = $_[0]; # interval in seconds |
57
|
2
|
|
50
|
|
|
25
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
58
|
2
|
50
|
|
|
|
5
|
return '0 sekunder' unless $span; |
59
|
2
|
|
|
|
|
8
|
_render('%s', |
60
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span)); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub duration { |
64
|
14
|
|
|
14
|
0
|
3017
|
my $span = $_[0]; # interval in seconds |
65
|
14
|
|
100
|
|
|
95
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
66
|
14
|
100
|
|
|
|
39
|
return '0 sekunder' unless $span; |
67
|
12
|
|
|
|
|
42
|
_render('%s', |
68
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
69
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span))); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub interval_exact { |
75
|
31
|
|
|
31
|
0
|
43
|
my $span = $_[0]; # interval, in seconds |
76
|
|
|
|
|
|
|
# precision is ignored |
77
|
31
|
100
|
|
|
|
103
|
my $direction = ($span <= -1) ? $_[2] # what a neg number gets |
|
|
50
|
|
|
|
|
|
78
|
|
|
|
|
|
|
: ($span >= 1) ? $_[3] # what a pos number gets |
79
|
|
|
|
|
|
|
: return $_[4]; # what zero gets |
80
|
30
|
|
|
|
|
95
|
_render($direction, |
81
|
|
|
|
|
|
|
Time::Duration::_separate($span)); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub interval { |
85
|
86
|
|
|
86
|
0
|
210
|
my $span = $_[0]; # interval, in seconds |
86
|
86
|
|
100
|
|
|
482
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
87
|
86
|
100
|
|
|
|
338
|
my $direction = ($span <= -1) ? $_[2] # what a neg number gets |
|
|
100
|
|
|
|
|
|
88
|
|
|
|
|
|
|
: ($span >= 1) ? $_[3] # what a pos number gets |
89
|
|
|
|
|
|
|
: return $_[4]; # what zero gets |
90
|
76
|
|
|
|
|
915
|
_render($direction, |
91
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
92
|
|
|
|
|
|
|
Time::Duration::_separate($span))); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
97
|
|
|
|
|
|
|
my %env2sv = ( |
98
|
|
|
|
|
|
|
second => ['sekund', 'sekunder'], |
99
|
|
|
|
|
|
|
minute => ['minut', 'minuter'], |
100
|
|
|
|
|
|
|
hour => ['timme', 'timmar'], |
101
|
|
|
|
|
|
|
day => ['dag','dagar'], |
102
|
|
|
|
|
|
|
year => ['år','år'], |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _render { |
108
|
|
|
|
|
|
|
# Make it into English |
109
|
1
|
|
|
1
|
|
1620
|
use Data::Dumper; |
|
1
|
|
|
|
|
34573
|
|
|
1
|
|
|
|
|
261
|
|
110
|
|
|
|
|
|
|
|
111
|
120
|
|
|
120
|
|
10064
|
my $direction = shift @_; |
112
|
600
|
100
|
|
|
|
2851
|
my @wheel = map |
|
|
100
|
|
|
|
|
|
113
|
|
|
|
|
|
|
{ |
114
|
120
|
|
|
|
|
219
|
( $_->[1] == 0) ? () # zero wheels |
115
|
|
|
|
|
|
|
: $_->[1] . ' ' . $env2sv{ $_->[0] }[ $_->[1] == 1 ? 0 : 1 ] |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
@_; |
118
|
|
|
|
|
|
|
|
119
|
120
|
50
|
|
|
|
510
|
return "just now" unless @wheel; # sanity |
120
|
120
|
|
|
|
|
157
|
my $result; |
121
|
120
|
100
|
|
|
|
7402
|
if(@wheel == 1) { |
|
|
100
|
|
|
|
|
|
122
|
48
|
|
|
|
|
79
|
$result = $wheel[0]; |
123
|
|
|
|
|
|
|
} elsif(@wheel == 2) { |
124
|
34
|
|
|
|
|
68
|
$result = "$wheel[0] och $wheel[1]"; |
125
|
|
|
|
|
|
|
} else { |
126
|
38
|
|
|
|
|
81
|
$wheel[-1] = "och $wheel[-1]"; |
127
|
38
|
|
|
|
|
95
|
$result = join q{, }, @wheel; |
128
|
|
|
|
|
|
|
} |
129
|
120
|
|
|
|
|
10688
|
return sprintf($direction, $result); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |