Skip to content

Commit

Permalink
Correct seconds calculations, "all day" bug
Browse files Browse the repository at this point in the history
fixes matthiasanderer#4 

Set seconds variables to actual seconds instead of minutes.
Include start and end hours in check for "all day" status - if time is "11:00:00" to "12:00:00" it should show as one hour, not "all day".
  • Loading branch information
will-russell authored Sep 4, 2019
1 parent 8f43191 commit 2218c7e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions icsFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ var icsFormatter = function() {
var start_day = ("00" + ((start_date.getDate()).toString())).slice(-2);
var start_hours = ("00" + (start_date.getHours().toString())).slice(-2);
var start_minutes = ("00" + (start_date.getMinutes().toString())).slice(-2);
var start_seconds = ("00" + (start_date.getMinutes().toString())).slice(-2);
var start_seconds = ("00" + (start_date.getSeconds().toString())).slice(-2);

var end_year = ("0000" + (end_date.getFullYear().toString())).slice(-4);
var end_month = ("00" + ((end_date.getMonth() + 1).toString())).slice(-2);
var end_day = ("00" + ((end_date.getDate()).toString())).slice(-2);
var end_hours = ("00" + (end_date.getHours().toString())).slice(-2);
var end_minutes = ("00" + (end_date.getMinutes().toString())).slice(-2);
var end_seconds = ("00" + (end_date.getMinutes().toString())).slice(-2);
var end_seconds = ("00" + (end_date.getSeconds().toString())).slice(-2);

// Since some calendars don't add 0 second events, we need to remove time if there is none...
var start_time = '';
var end_time = '';
if (start_minutes + start_seconds + end_minutes + end_seconds !== 0) {
if (start_hours + start_minutes + start_seconds + end_hours + end_minutes + end_seconds !== 0) {
// If time is midnight to midnight - then this is an all day event. Only add time if it's not
start_time = 'T' + start_hours + start_minutes + start_seconds;
end_time = 'T' + end_hours + end_minutes + end_seconds;
}
Expand Down

0 comments on commit 2218c7e

Please sign in to comment.