soroush / libcalendars Goto Github PK
View Code? Open in Web Editor NEWCollection of calendar arithmetic algorithms
License: GNU General Public License v3.0
Collection of calendar arithmetic algorithms
License: GNU General Public License v3.0
The official calendar in Iran is an unknown combination of Birashk's method and 33-years algorithm, with some exceptions added. These exceptions are not handled in this library, so retrospectively speaking, there will be +-1 day shifts in JDN calculations for some years before 1375.
For future year numbers, there is no known calendar release or schedule ahead of the time, so we will have no means to calculate day shift for them.
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
Just use the lib as normal way with the following script:
#include <libcalendars/cl-solar-hijri.h>
#define IRAN_TIME_ZONE_DIFF 12600U // UTC + 03:30(12600s)
float toJD(uint32_t epoch) {
return (epoch / 86400.0) + 2440587.5;
}
int main(int argc, char *argv[]) {
uint32_t epoch = 1521318959U; // 20:35:59 PM
uint32_t JD = toJD(epoch + IRAN_TIME_ZONE_DIFF); // 00:05:59 AM
int16_t jy;
uint8_t jm;
uint16_t jd;
jdn_to_sh(JD, &jy, &jm, &jd);
printf("\n Jalali: %d/%d/%d\n", jy, jm, jd);
system("pause");
return 0;
}
We're 359 second(00:05:59
) past the 1396/12/26
and we expect to see 1396/12/27
The jdn_to_sh(...)
calculate date as 1396/12/26
Operating system: Microsoft Windows 10(build 16299.309)
Compiler: MSVC2015(14.0)
Version of libcalendars: latest git version
Regards.
IMAN.
Hi
I tried to compile branch add_timestamp and it seams cl-tz.h is missing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.