Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix and improve timezone related functions #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions GmailUtils.gs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ function processUnread(query, limit, callback) {
}

/**
* Wrapper for Utilities.formatDate() which provides sensible defaults
* Wrapper for Utilities.formatDate() which provides sensiblea defaults
*
* @method formatDate
* @param {string} message
* @param {string} date //Change from 'message' to 'date' to make it not limited to gmail messages, then can be invoked anywhere in the project.
* @param {string} format
* @param {string} timezone
* @return {string} Formatted date
*/
function formatDate(message, format, timezone) {
function formatDate(date, format, timezone) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change from 'message' to 'date' to unlock the limitation

timezone = timezone || localTimezone_();
format = format || "MMMMM dd, yyyy 'at' h:mm a '" + timezone + "'";
return Utilities.formatDate(message.getDate(), timezone, format)
return Utilities.formatDate(new Date(date), timezone, format)
}

/**
Expand Down Expand Up @@ -193,7 +193,7 @@ function messageToHtml(messages, opts) {
var message = messages[m],
subject = message.getSubject(),
avatar = null,
date = formatDate(message),
date = formatDate(message.getDate()),
from = formatEmails_(message.getFrom()),
to = formatEmails_(message.getTo()),
cc = formatEmails_(message.getCc()),
Expand Down Expand Up @@ -500,8 +500,8 @@ function defaults_(options, defaults) {
* @return {string}
*/
function localTimezone_() {
var timezone = new Date().toTimeString().match(/\(([a-z0-9]+)\)/i);
return timezone.length ? timezone[1] : 'GMT';
var timezone = CalendarApp.getDefaultCalendar().getTimeZone();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CalendarApp to get default timezone to fix the issue

return timezone.length ? timezone : 'GMT';
}

/**
Expand Down