Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unix timestamp #2

Open
soroush opened this issue May 31, 2018 · 2 comments
Open

Add support for unix timestamp #2

soroush opened this issue May 31, 2018 · 2 comments

Comments

@soroush
Copy link
Owner

soroush commented May 31, 2018

Support for converting unix timestamp to the Solar Hijri calendar is added. This is an early implementation that needs to be carefully tested and if everything goes well, I will release a version containing the same arithmetic for all calendar/timezone pairs. The code is in currently in add_timestamp branch.

Please test this feature as far as you can. Following is a simple test program to validate any input data.

#include <stdio.h>
#include <stdint.h>
#include <libcalendars/cl-solar-hijri.h>
#include <libcalendars/cl-gregorian.h>

int main() {
    time_t ts[] = {1421107199, 1521318959, 1508592260,
                   1521307799, 1521307800
                  };
    for(size_t i = 0; i < (sizeof(ts) / sizeof(ts[0])); ++i) {
        int16_t jy;
        uint8_t jm;
        uint16_t jd;
        uint8_t h;
        uint8_t m;
        uint8_t s;
        ts_to_sh(ts[i], 12600, &jy, &jm, &jd, &h, &m, &s);
        struct tm* gm = gmtime(&ts[i]);
        printf("%ld = %02d/%02d/%02d %02d:%02d:%02d %hu/%02d/%02d %02d:%02d:%02d\n", ts[i],
               gm->tm_year+1900,
               gm->tm_mon+1,
               gm->tm_mday+1,
               gm->tm_hour,
               gm->tm_min,
               gm->tm_sec,
               jy, jm, jd, h, m, s);
    }
    return 0;
}

which results in:

1421107199 = 2015/01/13 23:59:59 1393/10/23 03:29:59
1521318959 = 2018/03/18 20:35:59 1396/12/27 00:05:59
1508592260 = 2017/10/22 13:24:20 1396/07/29 16:54:20
1521307799 = 2018/03/18 17:29:59 1396/12/26 20:59:59
1521307800 = 2018/03/18 17:30:00 1396/12/26 21:00:00
@soroush
Copy link
Owner Author

soroush commented May 31, 2018

@IMAN4K You might be interested in this.

@IMAN4K
Copy link

IMAN4K commented Jun 1, 2018

Well done @soroush
Sounds working fine.
I'll do more test ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants