-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (60 loc) · 1.36 KB
/
index.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
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
var moment = require('moment')
var rp = require('request-promise')
function getDesignation(now) {
return rp("https://www.dom.com/api/smart-pricing/years/" +
now.format("YYYY") + "/months/" + now.format("MMMM") + "?useEvents=true")
.then(function (data) {
data = JSON.parse(data)
var cleanData = {}
data.weeks.forEach(function (obj) {
obj.days.forEach(function (obj) {
if (obj.day != "") {
cleanData[obj.day] = obj.designation
}
})
})
return {designation: cleanData[now.format("D")]}
})
}
/**
* Status for today
*
* @returns {Promise}
*/
var today = function () {
return inDays()
}
/**
* Status for tomorrow
*
* @returns {Promise}
*/
var tomorrow = function () {
return inDays(1)
}
/**
* Gets the status for n number of days away
*
* @param {String|int} days can be negative
* @returns {Promise}
*/
var inDays = function (days) {
var now = moment()
now.add(days, "days")
return getDesignation(now)
}
/**
* Gets the status for based on date
*
* @param {Date} date
* @returns {Promise}
*/
var onDate = function (date) {
return getDesignation(moment(date))
}
module.exports = {
today: today,
tomorrow: tomorrow,
inDays: inDays,
onDate: onDate
}