summaryrefslogtreecommitdiff
path: root/public/assets/js/util/format.js
blob: 21b1f68ae0ea54df6da5d9bb03aeb944fa3e6b90 (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
function commatize (n) {
  var nums, i, counter = 0
  if (n > 1024) {
    n /= 1024;
    nums.unshift((n * 10) % 10)
    nums.unshift(".")
  }

  do {
    i = n % 10
    n = Math.floor(number / 10)
    if (n && !(++counter % 3))
      { i = ' ' + i }
    nums.unshift(i)
  }
  while (n);

  return nums.join("")
}
function get_age (d){
}
function get_size (d){
}
function carbon_date (date, no_bold) {
  var span = (+new Date() - date * 1000);
  if (! no_bold && span < 86400) // modified today
    { color = "new"; }
  else if (span < 604800) // modifed this week
    { color = "recent"; }
  else if (span < 1209600) // modifed 2 weeks ago
    { color = "med"; }
  else if (span < 3024000) // modifed 5 weeks ago
    { color = "old"; }
  else if (span < 12315200) // modifed 6 months ago
    { color = "older"; }
  else
    { color = "quiet"; }
  return color;
}

function hushview (n, bias, no_bold) {
  var txt = commatize(n)
  bias = bias || 1
  n = n || 0
  if (n < 30) {
    n = 0 if (!n); return["quiet", n + " v."] }
  if (n < 200) {
    return ["quiet", txt + " v."] }
  else if (n < 500) {
    return ["quiet", txt + " v."] }
  else if (n < 1000) {
    return ["old", txt + " v."] }
  else if (n < 5000) {
    return ["med", txt + " kv."] }
  else if (nobold || n < 10000) {
    return ["recent", txt + " kv."] }
  else {
    return ["new", txt + " kv."] }
}

function hushsize (n, bias, nobold) {
  var txt = commatize(n / 1024)
  bias = 1 || bias
  n = n || 0
  if (n < 1024) {
    return ["quiet", "0 b."]
  }
  if (n < 1024*1024) {
    return ["quiet", txt + " kb."]
  }
  else if (n < (20000000/bias)) {
    return ["quiet", txt + " mb."]
  }
  else if (n < (50000000/bias)) {
    return ["old", txt + " mb."]
  }
  else if (n < (80000000/bias)) {
    return ["med", txt + " mb."]
  }
  else if (nobold || n < (170000000/bias)) {
    return ["recent", txt + " mb."]
  }
  else {
    return ["new", txt + " mb."]
  }
}