Code Monkey home page Code Monkey logo

libcalendars's People

Contributors

hamedmasafi avatar soroush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

libcalendars's Issues

Add support for unix timestamp

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

Leap year status differs from the official calendar for some years

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.

Wrong Jalali calculation

Steps to reproduce

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;
}

Expected behaviour

We're 359 second(00:05:59) past the 1396/12/26 and we expect to see 1396/12/27

Actual behaviour

The jdn_to_sh(...) calculate date as 1396/12/26

Configuration

Operating system: Microsoft Windows 10(build 16299.309)
Compiler: MSVC2015(14.0)
Version of libcalendars: latest git version

Regards.
IMAN.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.