summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-08-04 08:25:02 +0200
committerYorhel <git@yorhel.nl>2021-08-04 08:25:02 +0200
commit6baa5582a2ff9015f3bd672e6c62570af6517903 (patch)
tree6e270a7e023ec157ce42b3310b943f9890710097 /lib
parent2f2a97fbe6705f02c1fe0d1ecc245f78637e5d7b (diff)
Adjust VN length formatting
Diffstat (limited to 'lib')
-rw-r--r--lib/VNWeb/HTML.pm13
-rw-r--r--lib/VNWeb/VN/Length.pm5
-rw-r--r--lib/VNWeb/VN/Page.pm12
3 files changed, 19 insertions, 11 deletions
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 70fa1b5b..78e59f2f 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -8,7 +8,7 @@ use Encode 'encode_utf8', 'decode_utf8';
use JSON::XS;
use TUWF ':html5_', 'uri_escape', 'html_escape', 'mkclass';
use Exporter 'import';
-use POSIX 'ceil', 'strftime';
+use POSIX 'ceil', 'floor', 'strftime';
use Carp 'croak';
use JSON::XS;
use VNDB::Config;
@@ -27,6 +27,7 @@ our @EXPORT = qw/
join_
user_ user_displayname
rdate rdate_
+ vnlength_
spoil_
elm_
framework_
@@ -119,6 +120,16 @@ sub rdate_ {
}
+sub vnlength_ {
+ my($l) = @_;
+ my $h = floor($l/60);
+ my $m = $l % 60;
+ txt_ "${h}h" if $h;
+ b_ class => 'grayedout', "${m}m" if $h && $m;
+ txt_ "${m}m" if !$h && $m;
+}
+
+
# Spoiler indication supscript (used for tags & traits)
sub spoil_ {
sup_ title => 'Minor spoiler', 'S' if $_[0] == 1;
diff --git a/lib/VNWeb/VN/Length.pm b/lib/VNWeb/VN/Length.pm
index 8ce1e927..b5d8d236 100644
--- a/lib/VNWeb/VN/Length.pm
+++ b/lib/VNWeb/VN/Length.pm
@@ -30,7 +30,7 @@ sub listing_ {
td_ class => 'tc1', sub { txt_ 'Date'; sortable_ 'date', $opt, \&url };
td_ class => 'tc2', sub { txt_ 'User'; sortable_ 'username', $opt, \&url } if $vn;
td_ class => 'tc2', sub { txt_ 'Title'; sortable_ 'title', $opt, \&url } if !$vn;
- td_ class => 'tc3', colspan => 2, sub { txt_ 'Time'; sortable_ 'length', $opt, \&url };
+ td_ class => 'tc3', sub { txt_ 'Time'; sortable_ 'length', $opt, \&url };
td_ class => 'tc4', sub { txt_ 'Speed'; sortable_ 'speed', $opt, \&url };
td_ class => 'tc5', 'Rel';
td_ class => 'tc6', 'Notes';
@@ -41,8 +41,7 @@ sub listing_ {
td_ class => 'tc2', sub {
a_ href => "/$_->{vid}", title => $_->{original}||$_->{title}, $_->{title};
} if !$vn;
- td_ class => 'tc3a', $_->{length} >= 60 ? floor($_->{length}/60).'h' : '';
- td_ class => 'tc3b', $_->{length} % 60 > 0 ? ($_->{length}%60).'m' : '';
+ td_ class => 'tc3', sub { vnlength_ $_->{length} };
td_ class => 'tc4', ['Slow','Normal','Fast']->[$_->{speed}];
td_ class => 'tc5', sub { a_ href => "/$_->{rid}", $_->{rid} };
td_ class => 'tc6', sub { lit_ bb_format $_->{notes}, inline => 1 };
diff --git a/lib/VNWeb/VN/Page.pm b/lib/VNWeb/VN/Page.pm
index 6e538595..f09634af 100644
--- a/lib/VNWeb/VN/Page.pm
+++ b/lib/VNWeb/VN/Page.pm
@@ -168,17 +168,15 @@ sub infobox_length_ {
my $my = auth->permLengthvote && tuwf->dbRowi('SELECT rid, length, speed, notes FROM vn_length_votes WHERE vid =', \$v->{id}, 'AND uid =', \auth->uid);
- my sub fmtlength {
- my($l) = @_;
- +($l>60?floor($l/60).'h':'').($l%60?sprintf '%dm', $l%60:'');
- }
-
tr_ sub {
td_ 'Length';
td_ sub {
if($stats->{count}) {
- txt_ fmtlength $stats->{avg};
- txt_ ' σ '.fmtlength $stats->{stddev} if $stats->{stddev};
+ vnlength_ $stats->{avg};
+ if ($stats->{stddev}) {
+ txt_ ' σ ';
+ vnlength_ $stats->{stddev};
+ }
txt_ ' (';
a_ href => "/$v->{id}/lengthvotes", sprintf '%d vote%s', $stats->{count}, $stats->{count}==1?'':'s';
txt_ ').';