corrade-nucleus-nucleons – Blame information for rev 10
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
10 | office | 1 | import absFloor from '../utils/abs-floor'; |
2 | var abs = Math.abs; |
||
3 | |||
4 | export function toISOString() { |
||
5 | // for ISO strings we do not use the normal bubbling rules: |
||
6 | // * milliseconds bubble up until they become hours |
||
7 | // * days do not bubble at all |
||
8 | // * months bubble up until they become years |
||
9 | // This is because there is no context-free conversion between hours and days |
||
10 | // (think of clock changes) |
||
11 | // and also not between days and months (28-31 days per month) |
||
12 | if (!this.isValid()) { |
||
13 | return this.localeData().invalidDate(); |
||
14 | } |
||
15 | |||
16 | var seconds = abs(this._milliseconds) / 1000; |
||
17 | var days = abs(this._days); |
||
18 | var months = abs(this._months); |
||
19 | var minutes, hours, years; |
||
20 | |||
21 | // 3600 seconds -> 60 minutes -> 1 hour |
||
22 | minutes = absFloor(seconds / 60); |
||
23 | hours = absFloor(minutes / 60); |
||
24 | seconds %= 60; |
||
25 | minutes %= 60; |
||
26 | |||
27 | // 12 months -> 1 year |
||
28 | years = absFloor(months / 12); |
||
29 | months %= 12; |
||
30 | |||
31 | |||
32 | // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js |
||
33 | var Y = years; |
||
34 | var M = months; |
||
35 | var D = days; |
||
36 | var h = hours; |
||
37 | var m = minutes; |
||
38 | var s = seconds; |
||
39 | var total = this.asSeconds(); |
||
40 | |||
41 | if (!total) { |
||
42 | // this is the same as C#'s (Noda) and python (isodate)... |
||
43 | // but not other JS (goog.date) |
||
44 | return 'P0D'; |
||
45 | } |
||
46 | |||
47 | return (total < 0 ? '-' : '') + |
||
48 | 'P' + |
||
49 | (Y ? Y + 'Y' : '') + |
||
50 | (M ? M + 'M' : '') + |
||
51 | (D ? D + 'D' : '') + |
||
52 | ((h || m || s) ? 'T' : '') + |
||
53 | (h ? h + 'H' : '') + |
||
54 | (m ? m + 'M' : '') + |
||
55 | (s ? s + 'S' : ''); |
||
56 | } |