Skip to content


Fix incorrect date header when in a timezone with +/- 30 mins #56

merged 1 commit into from

2 participants


Date headers should be like
Tue, 15 Jan 2013 14:45:11 -0430
but are like
Tue, 15 Jan 2013 14:45:16 -0450

For info on a time zone with a 30 min difference see

The original bug for including the date header had it correct with dateFormat but neither the Z or ZZ in moment are quite the same. My proposed fix isn't very elegant but it seems to work.


why do you think it isn't very elegant?


It just feels a little awkward to have to ask for another date format and then use replace on it. It would be prettier just to do .moment('ddd, DD MMM YYYY HH:mm:ss X') or something but I don't think we want to add another placeholder to moment.js.

Note: X = unix timestamp in moment.js.


why does moment.format("ZZ") not work?


also, what about using moment().zone() ?


RFC2822 says that time zones should be hhmm (page 14). The information here under "Email time zone indicator" supports my interpretation.

ZZ doesn't work as it gets the offset in hhff where ff = fraction of hour (50 instead of 30 minutes).

We could calculate it by getting the current zone (.zone()) and then extracting hours and minutes but personally, I prefer the .replace() method.

I created a fiddle to show this in action

@eleith eleith merged commit 9599399 into eleith:master

1 check failed

Details default The Travis build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2013
  1. @pedrosland
Showing with 1 addition and 1 deletion.
  1. +1 −1 smtp/message.js
2 smtp/message.js
@@ -35,7 +35,7 @@ var Message = function(headers)
var now = new Date();
this.header = {
"message-id":"<" + now.getTime() + "." + (counter++) + "." + + "@" + os.hostname() +">",
- "date":moment().format("ddd, DD MMM YYYY HH:mm:ss ZZ")
+ "date":moment().format("ddd, DD MMM YYYY HH:mm:ss ") + moment().format("Z").replace(/:/, '')
this.content = "text/plain; charset=utf-8";
Something went wrong with that request. Please try again.