summaryrefslogtreecommitdiff
path: root/date-fns/src/locale/nn/_lib/formatDistance/index.js
blob: cf716b63185823a71abd3e847823338a95a6728f (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var formatDistanceLocale = {
  lessThanXSeconds: {
    singular: 'mindre enn eitt sekund',
    plural: 'mindre enn {{count}} sekund'
  },

  xSeconds: {
    singular: 'eitt sekund',
    plural: '{{count}} sekund'
  },

  halfAMinute: 'eit halvt minutt',

  lessThanXMinutes: {
    singular: 'mindre enn eitt minutt',
    plural: 'mindre enn {{count}} minutt'
  },

  xMinutes: {
    singular: 'eitt minutt',
    plural: '{{count}} minutt'
  },

  aboutXHours: {
    singular: 'omtrent ein time',
    plural: 'omtrent {{count}} timar'
  },

  xHours: {
    singular: 'ein time',
    plural: '{{count}} timar'
  },

  xDays: {
    singular: 'ein dag',
    plural: '{{count}} dagar'
  },

  aboutXWeeks: {
    singular: 'omtrent ei veke',
    plural: 'omtrent {{count}} veker'
  },

  xWeeks: {
    singular: 'ei veke',
    plural: '{{count}} veker'
  },

  aboutXMonths: {
    singular: 'omtrent ein månad',
    plural: 'omtrent {{count}} månader'
  },

  xMonths: {
    singular: 'ein månad',
    plural: '{{count}} månader'
  },

  aboutXYears: {
    singular: 'omtrent eitt år',
    plural: 'omtrent {{count}} år'
  },

  xYears: {
    singular: 'eitt år',
    plural: '{{count}} år'
  },

  overXYears: {
    singular: 'over eitt år',
    plural: 'over {{count}} år'
  },

  almostXYears: {
    singular: 'nesten eitt år',
    plural: 'nesten {{count}} år'
  }
}

var wordMapping = [
  'null',
  'ein',
  'to',
  'tre',
  'fire',
  'fem',
  'seks',
  'sju',
  'åtte',
  'ni',
  'ti',
  'elleve',
  'tolv'
]

export default function formatDistance(token, count, options) {
  options = options || {
    onlyNumeric: false
  }

  var translation = formatDistanceLocale[token]
  var result
  if (typeof translation === 'string') {
    result = translation
  } else if (count === 0 || count > 1) {
    if (options.onlyNumeric) {
      result = translation.plural.replace('{{count}}', count)
    } else {
      result = translation.plural.replace(
        '{{count}}',
        count < 13 ? wordMapping[count] : count
      )
    }
  } else {
    result = translation.singular
  }

  if (options.addSuffix) {
    if (options.comparison > 0) {
      return 'om ' + result
    } else {
      return result + ' sidan'
    }
  }

  return result
}