nwcell / ics.js

A browser firendly VCS file generator written entirely in javascript!!!!!!
MIT License
620 stars 258 forks source link

Time doesn't show up if minutes and seconds are 0 #15

Closed karanveerm closed 7 years ago

karanveerm commented 10 years ago

If the time is like 12:00 pm, i.e. minutes are not provided, then the time does not show up in the ics calendar. For example:

var cal = ics();
cal.addEvent('Demo Event', 'This is a one hour event', 'location', '9/28/2014 12:00 pm', '9/28/2014 1:00 pm');
cal.download();

will be downloaded as an all day event.

I believe it will be fixed if we change: https://github.com/nwcell/ics.js/blob/master/ics.js#L77 to: if (start_hours + start_minutes + start_seconds + end_hours + end_minutes + end_seconds != 0) { (although I did not test this thoroughly)

visualxl commented 9 years ago

Nope. This is a bug. I spent a couple of hours on this since I am very new to JavaScript.

Do this under ics.js, and it will work fine:

//var start_seconds = ("00" + (start_date.getMinutes().toString())).slice(-2); //original
var start_seconds = ("00" + (start_date.getSeconds().toString())).slice(-2); //added by Syahmul

//var end_seconds = ("00" + (end_date.getMinutes().toString())).slice(-2); //original
var end_seconds = ("00" + (end_date.getSeconds().toString())).slice(-2); //added by Syahmul

To the one who is maintaining this repo, you may want to fix this bug as suggested here, and I hope it helps. :)

lynchkevin commented 9 years ago

It's not just that he is using .getMinutes() instead of .getSeconds his test also forgets the hours. karanveerm is exactly right if you change the code it does work but I also have not tested it exhaustively. Cost me as much time as this library saved me.

olafvanzon commented 9 years ago

I just created a pull request to fix this issue with solution suggested by @karanveerm.

@nwcell can you check? thanks

keiichi428 commented 7 years ago

So it's been 2 years since last post, but following change worked for me 👍

// if (start_minutes + start_minutes + start_seconds + end_minutes + end_seconds != 0) {
            if (start_hours +start_minutes + start_minutes + start_seconds + end_minutes + end_seconds != 0) {
                start_time = 'T' + start_hours + start_minutes + start_seconds;
                end_time = 'T' + end_hours + end_minutes + end_seconds;
            }
nwcell commented 7 years ago

Fixed