Archived Forum Post

Index of archived forum posts

Question:

Wrong GTM to UTC conversion CkDateTime

Mar 24 '17 at 08:33

Hi! I'm getting the validity information from a PFX certificate, and when I read the date using the conversion to UTC, the value of UTC is incorrect. Expected is -3, but CkDateTime is returning -2. In the operating system, GMT is -3.

My test code:

#include <iostream>
#include <string>

#include "CkCert.h"
#include "CkString.h"
#include "CkDateTime.h"

#define PATH_CERT "cert.pfx"
#define PASS_CERT "pass"

int main(void)
{
    CkCert* certificado = new CkCert();
    if (!certificado->LoadPfxFile(PATH_CERT, PASS_CERT))
    {
        std::cout << certificado->lastErrorText() << std::endl;
        delete certificado;
        return -1;
    }

    CkDateTime* certDtFrom;
    certDtFrom = certificado->GetValidFromDt();

    CkString* ckStr = new CkString();
    certDtFrom->GetAsRfc822(true, *ckStr);

    std::string valid(ckStr->getStringAnsi());
    std::cout << valid << std::endl;

    delete ckStr;
    delete certDtFrom;
    delete certificado;

    return 0;
}

Accepted Answer

When you get the local date/time for some date in the future (or some date in the past), the offset from GMT that you should see is the offset with Daylight Saving Time applied for that particular date/time, not for whatever exists right now.

For example, when Daylight Saving Time is in effect, the Eastern US timezone is UTC-4h, but when Daylight Saving Time is NOT in effect, the offset is UTC-5h.