Skip to content

Commit

Permalink
don't replicate bad date format for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Jul 27, 2015
1 parent 2930520 commit 376f3f5
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions testing/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports.get_cgm_record = function() {
var dateobj = new Date();
var datemil = dateobj.getTime();
var datesec = datemil / 1000;
var datestr = getDateString(dateobj);
var datestr = dateobj.toISOString();

// We put the time in a range from -1 to +1 for every thiry minute period
var range = (datesec % 1800) / 900 - 1.0;
Expand All @@ -26,47 +26,4 @@ exports.get_cgm_record = function() {
'direction': dir,
'dateString': datestr
};
};

//TODO: use moment
function getDateString(d) {

// How I wish js had strftime. This would be one line of code!

var month = d.getMonth();
var day = d.getDay();
var year = d.getFullYear();

if (month < 10) { month = '0' + month; }
if (day < 10) { day = '0' + day; }

var hour = d.getHours();
var min = d.getMinutes();
var sec = d.getSeconds();

var ampm = 'PM';
if (hour < 12) {
ampm = 'AM';
}

if (hour === 0) {
hour = 12;
}
if (hour > 12) {
hour = hour - 12;
}

if (hour < 10) {
hour = '0' + hour;
}

if (min < 10) {
min = '0' + min;
}

if (sec < 10) {
sec = '0' + sec;
}

return month + '/' + day + '/' + year + ' ' + hour + ':' + min + ':' + sec + ' ' + ampm;
}
};

0 comments on commit 376f3f5

Please sign in to comment.