Making a solar calendar. Hijri Shamsi (Persian, solar) to Gregorian calendar

What you need to know:

solar Hijir calender

The simple way is to link to Online calculator: The Muslim calendar. The Gregorian calendar conversion where you calculate this

You should be able convert from a western calendar with Blocks using the information at the Solar Hijri calendar link. Be aware, the process is very complex. convert gregorian to solar hijri calendar algorithm - Google Search contains links that shows how you might be able to make a converter with Java.

I don't want to make a converter but I want to display a hijri solar calendar on the screen where users can select the day and get the output.

Nobody knows?

I'm not familiar with the hijri solar calendar...
Can you provide some examples? What is the output after selecting a day?

As far as I understand, the app does not have to display the current day, month and year of the hirji solar calendar, else you would need a conversion as @SteveJG suggested...

I also don't understand your table from here

you might want to elaborate...

Taifun

If the user clicks on the calendar button, instead of the lunar date and its days, it should show the year 1401 and the days of Hijri Shams.

For example, if today is 2022 and July 22, it returns this according to the pattern
1401 and Tir 31

Another example is that if it is the first of January, it should return on Dey 11, and if it is the end of January, it should return on Bahman 11.

January1 = 11 DEY
end January = 11 Bahman
........

i.e. you want to create a Hijri Shamsi Calendar to Gregorian Calendar converter. The user types the date in Hijri Shamsi Calendar and the code converts it to Gregorian Calendar, like this page:

Yes, I ask the user to tell him the date in solar and the system returns the date to Gregorian so I can do whatever I want with this date.

:cold_face: :sob: :sob: :cry:

Why are you bumping this topic?

Also see here:

https://groups.google.com/g/mitappinventortest/c/c0Z9eXtfif8/m/K-0K2B7yDuIJ

I think the best thing is to adapt a JavaScript code, here we have one with an MIT license, but I think it's a lunar calendar:
https://github.com/xsoh/moment-hijri/blob/master/README.md

To use a solar calendar you can see the source code of this web page, I have not seen any information about its license to use.

https://calcuworld.com/calendar-calculators/persian-calendar-converter/

It is forbidden to reproduce, in whole or in part, to copy or to distribute the Content without the express permission from the owner. In no case the access and navigation of the User means a renunciation, transmission, licence and total or partial cession of the Website owner rights. In addition, it is forbidden to modify, copy, reuse, exploit, reproduce, publicly communicate, transmit, use, process or distribute anyhow the entire or part of the Content and elements of the Website for public or commercial purposes if the owner did not granted express and written permission.

So, in accordance with the previous paragraph, the User is permitted to not only visualize but also to print, copy or download the Content and Website elements as long as these actions are for personal and private use.

1 Like

Therefore, according to the contents right paragraph, we can use part of the code of the indicated website.

The Julian calendar, was proposed by Julius Caesar 46 [BC]. Roma. Solar.
The Gregorian calendar is a modification and replacement of the Julian calendar. Salamanca 1582. Solar.
And this is Julian day. (JD) (Converter)[Today 23 July 2022 is JD: 2459784]

In countries of Africa and Asia, solar and lunar calendars are frequently used.

Let's see a code to convert date in Hijri Shamsi (solar)(Persian, currently used in Iran and Afghanistan) to Gregorian.

https://www.bsswebsite.me.uk/Daysanddates/persian-date.html

If we consult the source code of that page, we will see the JavaScript code and a note indicating the origin of the code.
This calculator comes from www.calcuworld.com/calendar-calculators by Summon Press S.L., Calle Hospital, 1 Puerta 3-46001 Valencia (Spain).

We are going to use part of the code JavaScript to convert a date from Hijri Shamsi to Julian and to Gregorian.

Here the code...

<script>
     var PERSIAN_EPOCH = 1948320.5;

    datos =  window.AppInventor.getWebViewString(); // Entrada de datos App Inventor
  
    partes = datos.split(","); 
	var years = partes[0];
	var months = partes[1];
    var days = partes[2];
	
/*  MOD  --  Modulus function which works for non-integers.  (from file calendar.js original) */

function mod(a, b)
{
    return a - (b * Math.floor(a / b));
}
	
// PERSIAN_TO_JD -- Start data here

function persian_to_jd(year, month, day)
{
    var epbase, epyear;

    epbase = year - ((year >= 0) ? 474 : 473);
    epyear = 474 + mod(epbase, 2820);
    var salida = Number(day) +  Number(((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)))  +
            Number(Math.floor(((epyear * 682) - 110) / 2816))  +  
			Number((epyear - 1) * 365) +
			Number(Math.floor(epbase / 2820) * 1029983) +  
			Number(PERSIAN_EPOCH -1);
  //  window.AppInventor.setWebViewString(salida);  // Juliano. Respuesta a CadenaDeWebView
   return salida
}
 
//  LEAP_GREGORIAN  --  Is a given year in the Gregorian calendar a leap year ?

function leap_gregorian(year)
{
    return ((year % 4) == 0) &&
            (!(((year % 100) == 0) && ((year % 400) != 0)));
}

//  GREGORIAN_TO_JD  --  Determine Julian day number from Gregorian calendar date

var GREGORIAN_EPOCH = 1721425.5;

function gregorian_to_jd(year, month, day)
{
    return (GREGORIAN_EPOCH - 1) +
           (365 * (year - 1)) +
           Math.floor((year - 1) / 4) +
           (-Math.floor((year - 1) / 100)) +
           Math.floor((year - 1) / 400) +
           Math.floor((((367 * month) - 362) / 12) +
           ((month <= 2) ? 0 :
                               (leap_gregorian(year) ? -1 : -2)
           ) +
           day);
}

//  JD_TO_GREGORIAN  --  Calculate Gregorian calendar date from Julian day

function jd_to_gregorian(jd) {
    var wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad,
        yindex, dyindex, year, yearday, leapadj;

    wjd = Math.floor(jd - 0.5) + 0.5;
    depoch = wjd - GREGORIAN_EPOCH;
    quadricent = Math.floor(depoch / 146097);
    dqc = mod(depoch, 146097);
    cent = Math.floor(dqc / 36524);
    dcent = mod(dqc, 36524);
    quad = Math.floor(dcent / 1461);
    dquad = mod(dcent, 1461);
    yindex = Math.floor(dquad / 365);
    year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex;
    if (!((cent == 4) || (yindex == 4))) {
        year++;
    }
    yearday = wjd - gregorian_to_jd(year, 1, 1);
    leapadj = ((wjd < gregorian_to_jd(year, 3, 1)) ? 0
                                                  :
                  (leap_gregorian(year) ? 1 : 2)
              );
    month = Math.floor((((yearday + leapadj) * 12) + 373) / 367);
    day = (wjd - gregorian_to_jd(year, month, 1)) + 1;

	// Salida de calendario Gregoriano.
	 window.AppInventor.setWebViewString(year + "," + month + "," + day);  // Respuesta a CadenaDeWebView
    return new Array(year, month, day);
}

var juliano =  persian_to_jd(years,months,days);
var gregoriano = jd_to_gregorian(juliano);
</script>

Look at the Persian, Julian and Gregorian conversion algorithm.
As well as App Inventor data input and output.

calendario_persa.aia (3.6 KB)

persa

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.