Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

converting to my time given Mail Date

Posted on 1998-08-13
6
Medium Priority
?
194 Views
Last Modified: 2010-03-05
I need to be able to convert a date as shown by RFC822 (mail headers), to my localtime. I am working in Perl 5.

Say the input is:

"Wed, 12 Aug 1998 13:13:58 -0400"

I want the output to be:

Wed, 12 Aug 1998 13:13:58

but if the input is:

"Wed, 12 Aug 1998 13:13:58 -0300"

I want the output to be:

Wed, 12 Aug 1998 12:13:58

and be able to handle all the different timezones. I looked at GNUs and they don't do it, they just put the date as it comes with GMT, +0100, -0500. I would like to be able to convert the time to my local time.

anybody knows how I can do this in Perl?

BTW, I'm in Montreal, so I am -0400. I looked in tin code and they have a 400-line parser (yacc) to do this. Is there a way to do it in Perl. I have a function already that gives me the -0400 so take that as a given as well.
0
Comment
Question by:agj
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:b2pi
ID: 1209257
I don't think you meant to submit this question twice, you should be able to delete it.
0
 

Accepted Solution

by:
kaijen earned 1200 total points
ID: 1209258
Let's try:

$date = "Wed, 12 Aug 1998 13:13:58";
$date =~ m#(\w+,\s+\d+\s+\w+\s+\d+\s+)(\d+):(\d+):(\d+)(?:\s+(\+|-)?(\d{2}))?#;

$begin = $1;
$hour = $2;
$min = $3;
$sec = $4;
$sign = $5;
$diff = $6 if $6 ne "";
$diff = 0 if $6 eq "";

if ( $sign eq "-" )
{
      $hour += $diff - 4;
}
else
{
      $hour -= $diff + 4;
}

$date = "$begin$hour:$min:$sec";

print "$date\n";

should do the job.

Best regards,
Kai.
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1209259
Kai, what if the add or subtract of the hours takes you past midnight?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 85

Expert Comment

by:ozo
ID: 1209260
Well, it's too late to delete it now without help from customer support now that kaijen has locked it.
But what if the input is
"Wed, 12 Aug 1998 01:13:58 -0100"
0
 

Expert Comment

by:kaijen
ID: 1209261
Okay, you're right! Sorry for beeing so fast. I think the idea is clear and there's a lot more work to invest to consider midnight, month changing and new years day. If anyone has a shorthand solution for this please reject my answer and I volunteer for accepting this.

Okay?

Best regards,
Kai.
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1209262
Actually, agj accidentally submitted the question twice (it's actually easier to do than it should be.  The question has already been answered (basically, the answer was to use the Date::Manip package)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question