How to Convert Jalali date to Gregorian

hi
I want to convert Jalali date to Gregorian and display it on lcd
But I don’t know how to do it

The date can be converted by the following code, but I don’t know how to use it in ESPHome


def convert_gregorian_to_jalali(gy, gm, gd):

  if (gm > 12) or (gm < 1):
    raise ValueError('Invalid month number.')
  if (gd > 31) or (gd < 1):
    raise ValueError('Invalid day number.')
  g_day_count = (gy - 1) * 365 + (gy - 1) // 4 - (gy - 1) // 100 + (gy - 1) // 400
  for i in range(1, gm):
    if (i == 3):
      g_day_count += 1
    g_day_count += 31
  if (gm == 3) and (is_leap_year(gy)):
    g_day_count += 1
  j_day_count = g_day_count - 2279214
  j_year = (j_day_count // 365)
  j_day_count %= 365
  if (j_day_count > 305):
    j_year += 1
    j_day_count -= 365
  sh_month = (j_day_count // 30) + 1
  j_day_count %= 30
  sh_day = j_day_count + 1
  return j_year, sh_month, sh_day