Parsing email timestamps in Delphi/FreePascal

datetime, delphi, freepascal

Solution

if you use Synapse; in synautil.pas file you can find DecodeRfcDateTime function. With this function you can do what you ask.

Problem

Using FreePascal (FPC) 2.6.2 I'd like to convert into DateTime values some timestamp strings from email messages (retrieved from an IMAP server using Synapse `IMAPsend`): ``` Date: Thu, 1 Aug 2013 20:07:43 -0400 ``` From what I've read of `StrToDateTime()` and `TFormatSettings`, I don't see a way to do this directly. They typically expect strings like `1/8/2013 20:07:47` with formats like `dd/mm/yyyy` & `hh:mm:ss` and have no way to handle the UTC offset. Is it necessary for me to first chop-up and rearrange the string and do my own conversion of short month-names and offsets?

Original source