/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// map field value from gregorian calendar to hijri calendar void Calendar_hijri::mapFromGregorian()
{
sal_Int32 month, day, year;
day = static_cast<sal_Int32>(fieldValue[CalendarFieldIndex::DAY_OF_MONTH]);
month = static_cast<sal_Int32>(fieldValue[CalendarFieldIndex::MONTH]) + 1;
year = static_cast<sal_Int32>(fieldValue[CalendarFieldIndex::YEAR]); if (fieldValue[CalendarFieldIndex::ERA] == 0)
year *= -1;
// This function returns the Julian date/time of the Nth new moon since // January 1900. The synodic month is passed as parameter.
// Adapted from "Astronomical Formulae for Calculators" by // Jean Meeus, Third Edition, Willmann-Bell, 1985.
double
Calendar_hijri::NewMoon(sal_Int32 n)
{ double jd, t, t2, t3, k, ma, sa, tf, xtra;
k = n;
t = k/1236.85; // Time in Julian centuries from 1900 January 0.5
t2 = t * t;
t3 = t2 * t;
// Mean time of phase
jd = jd1900
+ SynPeriod * k
- 0.0001178 * t2
- 0.000000155 * t3
+ 0.00033 * sin(basegfx::deg2rad(166.56 + 132.87 * t - 0.009173 * t2));
// Sun's mean anomaly in radian
sa = basegfx::deg2rad(359.2242
+ 29.10535608 * k
- 0.0000333 * t2
- 0.00000347 * t3);
// Moon's mean anomaly
ma = basegfx::deg2rad(306.0253
+ 385.81691806 * k
+ 0.0107306 * t2
+ 0.00001236 * t3);
// Moon's argument of latitude
tf = 2.0 * basegfx::deg2rad(21.2964
+ 390.67050646 * k
- 0.0016528 * t2
- 0.00000239 * t3);
// Get Julian Day from Gregorian
sal_Int32 const julday = getJulianDay(*day, *month, *year);
// obtain approx. of how many Synodic months since the beginning of the year 1900
synmonth = static_cast<sal_Int32>(0.5 + (julday - jd1900)/SynPeriod);
// Number of month from reference point
nmonth = *month + *year * 12 - (GregRef * 12 + 1);
// Add Synodic Reference point
nmonth += SynRef;
// Get Julian days add time too
jday = NewMoon(nmonth) + *day;
// Round-up
jday = std::trunc(jday + 0.5);
// Use algorithm from "Numerical Recipes in C"
getGregorianDay(static_cast<sal_Int32>(jday), day, month, year);
// Julian -> Gregorian only works for non-negative year if ( *year <= 0 ) {
*day = -1;
*month = -1;
*year = -1;
}
}
/* this algorithm is taken from "Numerical Recipes in C", 2nd ed, pp 14-15. */ /* this algorithm only valid for non-negative gregorian year */ void
Calendar_hijri::getGregorianDay(sal_Int32 lJulianDay, sal_Int32 *pnDay, sal_Int32 *pnMonth, sal_Int32 *pnYear)
{ /* working variables */
tools::Long lFactorA, lFactorB, lFactorC, lFactorD, lFactorE;
/* test whether to adjust for the Gregorian calendar crossover */ if (lJulianDay >= GREGORIAN_CROSSOVER) { /* calculate a small adjustment */
tools::Long lAdjust = static_cast<tools::Long>((static_cast<float>(lJulianDay - 1867216) - 0.25) / 36524.25);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.