转换为印度教日历

www*_*com 45 php python java perl calendar

我怎么能转换unix时间印度教日历维基百科的时间和其他方式轮php,PerlPythonJava?我知道我可以转换为HebrewJewish.但Hindu不是一种选择.

更具体地说,我在谈论印度教的农历.以下网站正在运作,正是我想要的:http://web.meson.org/calendars/.例如,它将28-1-2012(格里高利)翻译成5-11-2068(Hind.Lun.).我怎样才能完成同样的任务?如果那里绝对没有抄写,我怎么能自己写呢?

rai*_*7ow 17

你检查了DateTime-Indic-0.1系列模块吗?至少DateTime :: Indic :: Chandramana 似乎有一种方法将传统日期转换为UTC值(utc_rd_values).

更新:

我想日历::坂可能是有用的,以及对于很多用户来说(我知道,这是印度国家日历),特别是to_gregorian()from_gregorian()方法.


Bur*_*lid 11

对于Python,请使用calendar2(注意:这不是内置日历模块).

样品用途:

>>> from calendar2 import *
>>> old_hindu_solar_from_absolute(absolute_from_gregorian(3,1,2012))
(11, 16, 5112)
>>> old_hindu_lunar_from_absolute(absolute_from_gregorian(3,1,2012))
(12, 0, 8, 5112)
Run Code Online (Sandbox Code Playgroud)


Pra*_*mar 8

论文:Indian Calendrical Calculations
在附录中提供了Common Lisp代码.

虽然可以根据论文编写Python(或其他语言)解决方案,但作者很好地列举了印度日历规则,因此如果您愿意考虑使用提供的Common Lisp代码,那么它是一篇非常可靠的论文.


Alp*_*Alp 5

似乎是一项艰巨的任务.根据在bytes.com上的讨论,没有明确的方法来实现100%正确的转换.但是当他们认为印​​度教日历只有364天而不是365天(或闰年为366天)时,他们似乎错了.

在这里你可以找到一个很好的转换表,包括闰年的处理:http://hinduism.about.com/od/basics/a/monthsdayseras.htm

如果它像写在那里一样容易,你可以尝试这样的东西(PHP代码):

<?php

function convertDateToHinduDate($date) {
    $beginningDayOfMonth = array(
        1 => 21,
        2 => 20,
        3 => 22 + (dateIsLeapYear($date) ? -1 : 0), /* 21 in leap years */
        4 => 21,
        5 => 22,
        6 => 22,
        7 => 23,
        8 => 23,
        9 => 23,
        10 => 23,
        11 => 22,
        12 => 22,
    );

    $daysOfHinduMonth = array(
        1 => 30 + (dateIsLeapYear($date) ? 1 : 0), /* 31 in leap years */
        2 => 31,
        3 => 31,
        4 => 31,
        5 => 31,
        6 => 31,
        7 => 30,
        8 => 30,
        9 => 30,
        10 => 30,
        11 => 30,
        12 => 30,
    );

    $day = (int) date('d', strtotime($date));
    $month = (int) date('m', strtotime($date));
    $year = (int) date('Y', strtotime($date));

    $monthBefore = $day < $beginningDayOfMonth[$month];
    $yearBefore = $month < 3 || ($month == 3 && $day < $beginningDayOfMonth[3]);

    $newYear = $year + 57 + ($yearBefore ? -1 : 0);
    $newMonth = $month - 2 + ($monthBefore ? -1 : 0);
    if($newMonth < 1) $newMonth = 12 + $newMonth;
    $newDay = $day - $beginningDayOfMonth[$month];
    if($newDay < 1) $newDay = $daysOfHinduMonth[$newMonth] + $newDay;

    return date("d-m-Y",  mktime(11, 59, 0, $newMonth, $newDay, $newYear));
}

function dateIsLeapYear($date) {
    return date('L', strtotime($date));
}

$date = date("d-m-Y", strtotime('2012-01-28'));

echo 'Date: ', $date, ' (is leap year: ', dateIsLeapYear($date) ? 'yes' : 'no', ')<br />';
echo 'Converted Hindu date: ', convertDateToHinduDate($date);
?>
Run Code Online (Sandbox Code Playgroud)

输出此代码:

Date: 28-01-2012 (is leap year: yes)
Converted Hindu date: 07-11-2068
Run Code Online (Sandbox Code Playgroud)

但根据这个Java小程序的计算器,它应该是05-11-2068而不是07-11-2068.因此,仍然缺少一些转换规则.也许你可以给我一些更多信息,以便我可以纠正上面的代码.