Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/converter.php
blob: 41951c7a575a3c39bbed2650fc2a418bbac9a45b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

# do not include twice
if (function_exists("format_time_duration"))
  return;

require_once "../init.php";

function format_time_duration($val) {
  $val = floor($val);
  $result = "";
  $result =
    sprintf(
      "%02d",
      $val % 60
    );
  $val = floor($val / 60);
  if ($val == 0)
    return $result;
  $result =
    sprintf(
      "%02d:%s",
      $val % 60,
      $result
    );
  $val = floor($val / 60);
  if ($val == 0)
    return $result;
  $result =
    sprintf(
      "%d:%s",
      $val % 24,
      $result
    );
  $val = floor($val / 24);
  if ($val == 0)
    return $result;
  $tmp = $val % 7;
  $printed_conjunction = true;
  if ($tmp > 1)
    $result =
      sprintf(
        "%d days and %s",
        $tmp,
        $result
      );
  elseif ($tmp == 1)
    $result =
      sprintf(
        "%d day and %s",
        $tmp,
        $result
      );
  else
    $printed_conjunction = false;
  $val = floor($val / 7);
  if ($val == 0)
    return $result;
  if ($printed_conjunction)
    $result =
      sprintf(
        ", %s",
        $result
      );
  else
    $result =
      sprintf(
        " and %s",
        $result
      );
  if ($val>1)
    $result =
      sprintf(
        "%d weeks%s",
        $val,
        $result
      );
  else
    $result =
      sprintf(
        "%d week%s",
        $val,
        $result
      );
  return $result;
}