PageSourceSearch

https://oceanproteinportal.org/static/assets/vendor/leaflet/leaflet.timedimension.util.js

js oceanproteinportal.org collected 2026-10-08 11:23:36 UTC 6,956 bytes, 198 lines download raw bytes

vendor: 6,956 bytes, lines 1-198
1/*
2 * L.TimeDimension.Util
3 */
4
5L.TimeDimension.Util = {
6    getTimeDuration: function(ISODuration) {
7        if (nezasa === undefined) {
8            throw "iso8601-js-period library is required for Leatlet.TimeDimension: https://github.com/nezasa/iso8601-js-period";
9        }
10        return nezasa.iso8601.Period.parse(ISODuration, true);
11    },
12
13    addTimeDuration: function(date, duration, utc) {
14        if (utc === undefined) {
15            utc = true;
16        }
17        if (typeof duration == 'string' || duration instanceof String) {
18            duration = this.getTimeDuration(duration);
19        }
20        var l = duration.length;
21        var get = utc ? "getUTC" : "get";
22        var set = utc ? "setUTC" : "set";
23
24        if (l > 0 && duration[0] != 0) {
25            date[set + "FullYear"](date[get + "FullYear"]() + duration[0]);
26        }
27        if (l > 1 && duration[1] != 0) {
28            date[set + "Month"](date[get + "Month"]() + duration[1]);
29        }
30        if (l > 2 && duration[2] != 0) {
31            // weeks
32            date[set + "Date"](date[get + "Date"]() + (duration[2] * 7));
33        }
34        if (l > 3 && duration[3] != 0) {
35            date[set + "Date"](date[get + "Date"]() + duration[3]);
36        }
37        if (l > 4 && duration[4] != 0) {
38            date[set + "Hours"](date[get + "Hours"]() + duration[4]);
39        }
40        if (l > 5 && duration[5] != 0) {
41            date[set + "Minutes"](date[get + "Minutes"]() + duration[5]);
42        }
43        if (l > 6 && duration[6] != 0) {
44            date[set + "Seconds"](date[get + "Seconds"]() + duration[6]);
45        }
46    },
47
48    subtractTimeDuration: function(date, duration, utc) {
49        if (typeof duration == 'string' || duration instanceof String) {
50            duration = this.getTimeDuration(duration);
51        }
52        var subDuration = [];
53        for (var i = 0, l = duration.length; i < l; i++) {
54            subDuration.push(-duration[i]);
55        }
56        this.addTimeDuration(date, subDuration, utc);
57    },
58
59    parseAndExplodeTimeRange: function(timeRange) {
60        var tr = timeRange.split('/');
61        var startTime = new Date(Date.parse(tr[0]));
62        var endTime = new Date(Date.parse(tr[1]));
63        var duration = tr.length > 2 ? tr[2] : "P1D";
64
65        return this.explodeTimeRange(startTime, endTime, duration);
66    },
67
68    explodeTimeRange: function(startTime, endTime, ISODuration, validTimeRange) {
69        var duration = this.getTimeDuration(ISODuration);
70        var result = [];
71        var currentTime = new Date(startTime.getTime());
72        var minHour = null,
73            minMinutes = null,
74            maxHour = null,
75            maxMinutes = null;
76        if (validTimeRange !== undefined) {
77            var validTimeRangeArray = validTimeRange.split('/');
78            minHour = validTimeRangeArray[0].split(':')[0];
79            minMinutes = validTimeRangeArray[0].split(':')[1];
80            maxHour = validTimeRangeArray[1].split(':')[0];
81            maxMinutes = validTimeRangeArray[1].split(':')[1];
82        }
83        while (currentTime < endTime) {
84            if (validTimeRange === undefined ||
85                (currentTime.getUTCHours() >= minHour && currentTime.getUTCHours() <= maxHour)
86            ) {
87                if ((currentTime.getUTCHours() != minHour || currentTime.getUTCMinutes() >= minMinutes) &&
88                    (currentTime.getUTCHours() != maxHour || currentTime.getUTCMinutes() <= maxMinutes)) {
89                    result.push(currentTime.getTime());
90                }
91            }
92            this.addTimeDuration(currentTime, duration);
93        }
94        if (currentTime >= endTime){
95            result.push(endTime.getTime());
96        }
97        return result;
98    },
99
100    parseTimeInterval: function(timeInterval) {
101        var parts = timeInterval.split("/");
102        if (parts.length != 2) {
103            throw "Incorrect ISO9601 TimeInterval: " + timeInterval;
104        }
105        var startTime = Date.parse(parts[0]);
106        var endTime = null;
107        var duration = null;
108        if (isNaN(startTime)) {
109            // -> format duration/endTime
110            duration = this.getTimeDuration(parts[0]);
111            endTime = Date.parse(parts[1]);
112            startTime = new Date(endTime);
113            this.subtractTimeDuration(startTime, duration, true);
114            endTime = new Date(endTime);
115        } else {
116            endTime = Date.parse(parts[1]);
117            if (isNaN(endTime)) {
118                // -> format startTime/duration
119                duration = this.getTimeDuration(parts[1]);
120                endTime = new Date(startTime);
121                this.addTimeDuration(endTime, duration, true);
122            } else {
123                // -> format startTime/endTime
124                endTime = new Date(endTime);
125            }
126            startTime = new Date(startTime);
127        }
128        return [startTime, endTime];
129    },
130
131    parseTimesExpression: function(times) {
132        var result = [];
133        if (!times) {
134            return result;
135        }
136        if (typeof times == 'string' || times instanceof String) {
137            var timeRanges = times.split(",");
138            var timeRange;
139            var timeValue;
140            for (var i=0, l=timeRanges.length; i<l; i++){
141                timeRange = timeRanges[i];
142                if (timeRange.split("/").length == 3) {                
143                    result = result.concat(this.parseAndExplodeTimeRange(timeRange));
144                } else {
145                    timeValue = Date.parse(timeRange);
146                    if (!isNaN(timeValue)) {
147                        result.push(timeValue);
148                    }
149                }
150            }
151        } else {
152            result = times;
153        }
154        return result.sort(function(a, b) {
155            return a - b;
156        });
157    },
158
159    intersect_arrays: function(arrayA, arrayB) {
160        var a = arrayA.slice(0);
161        var b = arrayB.slice(0);
162        var result = [];
163        while (a.length > 0 && b.length > 0) {
164            if (a[0] < b[0]) {
165                a.shift();
166            } else if (a[0] > b[0]) {
167                b.shift();
168            } else /* they're equal */ {
169                result.push(a.shift());
170                b.shift();
171            }
172        }
173        return result;
174    },
175
176    union_arrays: function(arrayA, arrayB) {
177        var a = arrayA.slice(0);
178        var b = arrayB.slice(0);
179        var result = [];
180        while (a.length > 0 && b.length > 0) {
181            if (a[0] < b[0]) {
182                result.push(a.shift());
183            } else if (a[0] > b[0]) {
184                result.push(b.shift());
185            } else /* they're equal */ {
186                result.push(a.shift());
187                b.shift();
188            }
189        }
190        if (a.length > 0) {
191            result = result.concat(a);
192        } else if (b.length > 0) {
193            result = result.concat(b);
194        }
195        return result;
196    }
197
198};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.