Parece ser una tarea difícil. De acuerdo con this discussion at bytes.com, no hay una forma clara de lograr una conversión correcta del 100%. Pero parece que están equivocados cuando suponen que el calendario hindú tiene solo 364 días en lugar de 365 (o 366 en años bisiestos).
Aquí se puede encontrar una buena tabla de conversión que incluye el manejo de los años bisiestos: http://hinduism.about.com/od/basics/a/monthsdayseras.htm
Si es tan fácil como está escrito allí se puede intentar algo como esto (código 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);
?>
salida de este código:
Date: 28-01-2012 (is leap year: yes)
Converted Hindu date: 07-11-2068
Sin embargo, según la calculadora de this Java applet, debe ser en lugar de 05.11.2068 07.11.2068. Por lo tanto, todavía faltan algunas reglas de conversión. Quizás puedas darme más información para que pueda corregir el código anterior.
Proporcione valores de ejemplo de cómo expresaría una fecha (marca de tiempo) cuando la escriba * Calendario hindú * -style. – hakre
De día, mes, año a día, mes, año es suficiente para nuestra aplicación. –
Eso no es lo que quería saber. Simplemente dé ejemplos múltiples, fecha hindú a la izquierda, la fecha gregoriana correspondiente a la derecha. Solo quiero saber de qué se trata ese calendario hindú cuando los valores de la fecha se expresan en un sitio web. – hakre