pixelcog / gmail-to-pdf

A Google Apps Script library for converting Gmail messages to PDFs for easy archival.
http://bit.ly/1CsBl8U
123 stars 38 forks source link

localtimezone_() and formatDate() not quite working for "EDT" #13

Open kailiangchen opened 5 years ago

kailiangchen commented 5 years ago

Hi @mikegreiling

I'm very thankful for your project and I'm using it. However I found one small problem. Basically, at least with my timezone "EDT" (Eastern Daylight Saving Time), localTimezone_() returns "EDT", but when Gmail.Utils.formatDate calls Utilities.formatDate(message.getDate(), timezone, format), it has problems taking "EDT" as the timezone input, and end up using "GMT" instead as the timezone. Therefore it ends up returning a date formatted with GMT timezone, not local timezone. While the format string is such that it still says "EDT", therefore the datetime string is wrong. (here)

I did find that (a hack) if I use Utilities.formatDate() and it would return "America/New_York", and with that as the timezone input, it gets Utilities.formatDate() working correctly. Hence the below work-around:

//my work-around
function myFormatDate(message, format) {
  return Utilities.formatDate(message.getDate(), Session.getScriptTimeZone(), format);
}

I'm using my work-around to replace Gmail.Utils.formatDate, but want to report this issue. Thx!