-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqueryURL.js
38 lines (33 loc) · 1.57 KB
/
queryURL.js
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
function QueryURL(baseURL, probeTag) {
this._baseURL = baseURL;
this._query = probeTag.query;
this.timeIntervalInMS = undefined;
this._latitude = probeTag.latitude;
this._longitude = probeTag.longitude;
this._radius = probeTag.radius;
}
QueryURL.prototype.getURL = function getURL() {
var since = '';
if(this.timeIntervalInMS !== undefined)
since = 'since='+ escape(this.getSinceDate());
var geoLoc = '';
if(this._latitude !== undefined && this._longitude !== undefined && this._radius !== undefined)
geoLoc = 'geocode=' + escape(this._latitude + ',' + this._longitude + ',' + this._radius + 'km');
var urlQuery = this._query !== undefined ? 'q=' + escape(this._query) : '';
var urlSince = since !== '' ? '&' + since : since;
var urlGeoLoc = geoLoc !== '' ? '&' + geoLoc : geoLoc;
queryURL = this._baseURL + urlQuery + urlSince + urlGeoLoc;
console.log('XHRQueryURL:' + queryURL);
return queryURL;
};
QueryURL.prototype.getSinceDate = function _getSinceDate() {
var currentTime = new Date();
console.log('currentTS: '+ currentTime.getTime() + ', Interval length: ' + this.timeIntervalInMS);
var sinceDate = new Date(currentTime.getTime() - this.timeIntervalInMS);
console.log('sinceTS: ' + sinceDate.getTime());
var sinceYear = sinceDate.getFullYear();
var sinceMonth = sinceDate.getMonth() >= 10 ? sinceDate.getMonth() : '0' + sinceDate.getMonth();
var sinceDay = sinceDate.getDay() >= 10 ? sinceDate.getDay() : '0' + sinceDate.getDay();
console.log('Since: ' + sinceYear + '-' + sinceMonth + '-' + sinceDay);
return sinceYear + '-' + sinceMonth + '-' + sinceDay;
};