SMTP Date format?

B

Ben Giddings

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

What exactly can strftime not do for you?

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

Date: Wed, 23 Jul 2003 22:35:49 +0900
^^^^^

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
 
B

Brian Candler

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).

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/<whatever>; 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.
 
J

Josef 'Jupp' Schugt

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
 
B

Brian Candler

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top