Skip to content

Instantly share code, notes, and snippets.

@zymr-keshav
Created August 14, 2017 06:43
Show Gist options
  • Save zymr-keshav/244e21703dcba59973146648e1ccf3c2 to your computer and use it in GitHub Desktop.
Save zymr-keshav/244e21703dcba59973146648e1ccf3c2 to your computer and use it in GitHub Desktop.
create default 12 hours tiem data with difference of 1 hour
const getDatesRangeArray = function(startDate, endDate, unit, step) {
// console.log("getDatesRangeArray", arguments);
var interval = {
unit_: unit || 'hours',
step_: step || 1
},
dateArray = [],
currentDate = startDate;
// console.log("currentDate", currentDate);
while (currentDate <= endDate) {
// console.log('dateArray', dateArray);
dateArray.push(currentDate);
currentDate = moment(currentDate).add(interval.step_, interval.unit_).utc().valueOf(); // in milliseconds
// console.log("new currentDate in while", currentDate);
}
// console.log("final dateArray", dateArray);
return dateArray;
};
const createDefaultTimeChart = function() {
//console.log("createDefaultLineChart");
let endHour = moment().utc().valueOf(); // current timestamp
let startHour = moment(endHour).subtract(11, 'hours').utc().valueOf(); // current timestamp - 12 hours
getDatesRangeArray(startHour, endHour, 'hours', 1).then(function(timeSheet) {
console.log("timeSheet", timeSheet);
// vm.lineGraph.create(timeSheet);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment