SMTP Date format?

Hey all,

Is there already code which formats a date into the format required for SMTP?

http://ftp.rfc-editor.org/in-notes/rfc2822.txt

See sec 3.3

I’ve been writing my own version, but it really seems like it must have
already been done.

Ben

In article 200307221635.02170.ben@thingmagic.com,
Ben Giddings ben@thingmagic.com writes:

Is there already code which formats a date into the format required for SMTP?

http://ftp.rfc-editor.org/in-notes/rfc2822.txt

time.rb which is bundled since 1.6.7 has Time#rfc2822.

% ruby -rtime -e ‘p Time.now.rfc2822’
“Wed, 23 Jul 2003 09:29:05 +0900”

···


Tanaka Akira

Saluton!

  • Ben Giddings; 2003-07-22, 20:38 UTC:

Is there already code which formats a date into the format required
for SMTP?

What exactly can strftime not do for you?

Josef ‘Jupp’ Schugt

  • Ben Giddings; 2003-07-22, 20:38 UTC:

Is there already code which formats a date into the format required
for SMTP?

What exactly can strftime not do for you?

Well the tough part was going to be the timezone offset part:

                            ^^^^^

But now that I found the time library which does the formatting I’m set.

While we’re on the subject though, what’s the recommended method for
determining your timezone offset in Ruby?

Ben

···

On Wed July 23 2003 9:35 am, Josef ‘Jupp’ Schugt wrote:
Date: Wed, 23 Jul 2003 22:35:49 +0900

On my system (at home) the only reliable method would be asking the
user to provide it. The machine is running on UTC while the official
timezone is MESZ (UTC+2).

Josef ‘Jupp’ Schugt

···

On Thu, 24 Jul 2003, Ben Giddings wrote:

But now that I found the time library which does the formatting I’m
set.

While we’re on the subject though, what’s the recommended method
for determining your timezone offset in Ruby?

~$ ri Time
This is a test ‘ri’. Please report errors and omissions
on http://www.rubygarden.org/ruby?RIOnePointEight

···

On Thu, 24 Jul 2003 00:32:33 +0900 Ben Giddings ben@thingmagic.com wrote:

While we’re on the subject though, what’s the recommended method for
determining your timezone offset in Ruby?


 class: Time

 Time is an abstraction of dates and times. Time is stored
 internally as the number of seconds and microseconds since the
 epoch, January 1, 1970 00:00 UTC. On some operating systems, this
 offset is allowed to be negative. Also see the library modules Date
 and ParseDate, documented beginning on pages ?? and ??,
 respectively. The Time class treats GMT (Greenwich Mean Time) and
 UTC (Coordinated Universal Time)[Yes, UTC really does stand for
 Coordinated Universal Time. There was a committee involved.] as
 equivalent. GMT is the older way of referring to these baseline
 times but persists in the names of calls on Posix systems.
 All times are stored with some number of microseconds. Be aware of
 this fact when comparing times with each other---times that are
 apparently equal when displayed may be different when compared.

 +, -, <=>, asctime, at, ctime, day, dst?, getgm, getlocal, getutc,
 gm, gmt?, gmt_offset, gmtime, gmtoff, hour, isdst, local,
 localtime, mday, min, mktime, mon, month, new, now, sec, strftime,
 times, to_a, to_f, to_i, to_s, tv_sec, tv_usec, usec, utc, utc,
 utc?, utc_offset, wday, yday, year, zone

~$ ri Time.gmt_offset
This is a test ‘ri’. Please report errors and omissions
on http://www.rubygarden.org/ruby?RIOnePointEight

-------------------------------------------------------- Time#gmt_offset
time.gmt_offset → aFixnum

 Returns the offset in seconds between the timezone of time and UTC.
    t = Time.gm(2000,1,1,20,15,1)   #=> Sat Jan 01 20:15:01 UTC 2000
    t.gmt_offset                    #=> 0
    l = t.getlocal                  #=> Sat Jan 01 14:15:01 CST 2000
    l.gmt_offset                    #=> -21600

Jason Creighton

But Unix machines, although they “run” on UTC, can be configured with a
local timezone. This is the time you will see when you run the ‘date’
command, for example. On most machines I’ve seen this is set by creating
/etc/localtime as a symlink to /usr/share/zoneinfo/; it can also
be overriden by setting environment variable TZ.

In many parts of the world the timezone offset varies throughout the year,
but with a modern implementation of localtime() it will tell you it:

#include <stdio.h>
#include <time.h>
int main(void)
{
time_t now = time(NULL);
struct tm *tm = localtime(&now);
printf(“The current timezone name is %s\n”,tm->tm_zone);
printf(“The current timezone offset is %ld secs from GMT\n”,tm->tm_gmtoff);
return 0;
}

When I run this I get:

The current timezone name is BST
The current timezone offset is 3600 secs from GMT

(I am in the UK). So the information is there - whether there’s a Ruby
wrapper for it I don’t know.

If you’re on a Windows machine though, you’re in a whole different sorry
state. At work I get E-mails from people using Outlook calendar saying
“meeting scheduled for 14:00 GMT (London, Lisbon, …)” when in fact they
mean 2pm local time, which in the summer is 13:00 GMT. The clock is actually
moved forwards and backwards when daylight savings starts and ends, instead
of calculating the offset. If you turn your computer on at 1.30am on the day
that the change takes place, your computer has no idea what the correct time
is.

Cheers,

Brian.

···

On Thu, Jul 24, 2003 at 01:22:33AM +0900, Josef ‘Jupp’ Schugt wrote:

On Thu, 24 Jul 2003, Ben Giddings wrote:

But now that I found the time library which does the formatting I’m
set.

While we’re on the subject though, what’s the recommended method
for determining your timezone offset in Ruby?

On my system (at home) the only reliable method would be asking the
user to provide it. The machine is running on UTC while the official
timezone is MESZ (UTC+2).

Saluton!

  • Brian Candler; 2003-07-24, 12:25 UTC:

When I run this I get:

The current timezone name is BST
The current timezone offset is 3600 secs from GMT

UTC, no offset here. Principle of least trouble.

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon

I don’t believe in BST so there’s no surprise that all my systems here, in
London, report:

The current timezone name is GMT
The current timezone offset is 0 secs from GMT

Which is as it should be.

Regards, Trevor

<>< Re: deemed!

···

On Fri, 25 Jul 2003 04:00:09 +0900, Josef ‘Jupp’ Schugt jupp@gmx.de wrote:

Saluton!

  • Brian Candler; 2003-07-24, 12:25 UTC:

When I run this I get:

The current timezone name is BST
The current timezone offset is 3600 secs from GMT

UTC, no offset here. Principle of least trouble.

Well, each to his own. If you’re parsing crappy log files that don’t store
the time unambiguously, then I agree that local time could be a problem.

Cheers,

Brian.

···

On Fri, Jul 25, 2003 at 04:14:25AM +0900, Trevor Jenkins wrote:

I don’t believe in BST so there’s no surprise that all my systems here, in
London, report:

The current timezone name is GMT
The current timezone offset is 0 secs from GMT

Which is as it should be.