burmesedate.burme

Getting Burmese Calendar Data

  1# /* cSpell:disable */
  2"""
  3# Getting Burmese Calendar Data
  4
  5"""
  6
  7import math
  8from typing import List, Tuple
  9
 10
 11def b1_search(k: int, a: List[Tuple[int, str]]) -> int:
 12    """
 13    Perform a binary search on a sorted list of tuples.1 D array
 14
 15    Parameters:
 16    - k (int): The key to search for.
 17    - A (List[Tuple[int, str]]): The sorted list of tuples to search in.
 18
 19    Returns:
 20    - int: The index of the found key in the list, or -1 if the key is not found.
 21
 22    Notes:
 23    - The function assumes that the list of tuples is sorted in ascending
 24     order based on the first element of each tuple.
 25    - The function uses a binary search algorithm to find the key in the list.
 26    - The function returns the index of the found key in the list,
 27      or -1 if the key is not found.
 28
 29    Example:
 30    >>> b1_search(5, [(1, 'a'), (3, 'b'), (5, 'c'), (7, 'd'), (9, 'e')])
 31    2
 32    """
 33    u = len(a) - 1
 34    l = 0
 35
 36    while u >= l:
 37        i = (l + u) // 2
 38        z = a[i]
 39
 40        if z > k:
 41            u = i - 1
 42        elif z < k:
 43            l = i + 1
 44        else:
 45            return i
 46
 47    return -1
 48
 49
 50def b2_search(k: int, a: List[Tuple[int, str]]) -> int:
 51    """
 52    Perform a binary search on a list of tuples.2 D array
 53
 54    Parameters:
 55    - k (int): The key to search for.
 56    - a (List[Tuple[int, str]]): The list of tuples to search in.
 57
 58    Returns:
 59    - int: The index of the tuple that matches the key, or -1 if no match is found.
 60
 61    Notes:
 62    - The function assumes that the list of tuples is sorted in ascending order
 63      based on the first element of each tuple.
 64    - The function uses a binary search algorithm to find the key in the list.
 65    - The function returns the index of the tuple that matches the key, or -1 if no match is found.
 66
 67    Example:
 68    >>> b2_search(5, [(1, 'a'), (3, 'b'), (5, 'c'), (7, 'd'), (9, 'e')])
 69    2
 70    """
 71    u = len(a) - 1
 72    l = 0
 73
 74    while u >= l:
 75        i = (l + u) // 2
 76        z = a[i][0]
 77
 78        if z > k:
 79            u = i - 1
 80        elif z < k:
 81            l = i + 1
 82        else:
 83            return i
 84
 85    return -1
 86
 87
 88def get_my_const(my: int) -> dict:
 89    """
 90    ## Return a dictionary of constants based on the given Burmese calendar era.
 91
 92    ### Parameters:
 93    - my (int): The Burmese year to check.
 94
 95    ### Returns:
 96    - dict: A dictionary containing the following constants:
 97        - ei (float): Burmese calendar era ID [1-3]
 98          calculations methods/constants depend on era.
 99        - wo (float): Watat offset to compensate.
100        - nm (int): Number of months to find excess days.
101        - ew (int): Exception in watat year.
102
103    ### Notes:
104    - The function uses binary search algorithms (b1_search and b2_search)
105      to find exceptions in the calendar eras.
106    - The constants are determined based on the given Burmese calendar era ID (my).
107    - The function returns a dictionary with the calculated constants.
108
109    ### Dependencies
110        - `burmethon.helper.main.b1_search`
111        - `burmethon.helper.main.b2_search`
112
113    ### Example:
114
115    >>> get_my_const(1312)
116    {'ei': 3, 'wo': -0.5, 'NM': 8, 'ew': 0}
117    """
118    ei = 0
119    wo = 0
120    nm = 0
121    ew = 0
122
123    if my >= 1312:  # The third era (the era after Independence 1312 ME and after)
124        ei = 3
125        wo = -0.5
126        nm = 8
127        fme = [[1377, 1]]
128        wte = [1344, 1345]
129    # The second era (the era under British colony: 1217 ME - 1311 ME)
130    elif my >= 1217:
131        ei = 2
132        wo = -1
133        nm = 4
134        fme = [[1234, 1], [1261, -1]]
135        wte = [1344, 1345]
136    # The first era (the era of Burmese kings: ME1216 and before)
137    elif my >= 1100:
138        # Thandeikta (ME 1100 - 1216)
139        ei = 1.3
140        wo = -0.85
141        nm = -1
142        fme = [[1120, 1], [1126, -1], [1150, 1], [1172, -1], [1207, 1]]
143        wte = [1201, 1202]
144    elif my >= 798:  # Makaranta system 2 (ME 798 - 1099)
145        ei = 1.2
146        wo = -1.1
147        nm = -1
148        fme = [
149            [205, 1],
150            [246, 1],
151            [471, 1],
152            [572, -1],
153            [651, 1],
154            [653, 2],
155            [656, 1],
156            [672, 1],
157            [729, 1],
158            [767, -1],
159        ]
160        wte = []
161    else:  # Makaranta system 1 (ME 0 - 797)
162        ei = 1.1
163        wo = -1.1
164        nm = -1
165        fme = [
166            [205, 1],
167            [246, 1],
168            [471, 1],
169            [572, -1],
170            [651, 1],
171            [653, 2],
172            [656, 1],
173            [672, 1],
174            [729, 1],
175            [767, -1],
176        ]
177        wte = []
178
179    # full moon day offset exceptions
180    i = b2_search(my, fme)
181    if i >= 0:
182        wo += fme[i][1]
183
184    # correct watat exceptions
185    i = b1_search(my, wte)
186    if i >= 0:
187        ew = 1
188
189    return {"ei": ei, "wo": wo, "nm": nm, "ew": ew}
190
191
192def calculate_watat(my):
193    """
194    Check watat (intercalary month).
195
196    Parameters:
197    - my (int): The year to check.
198
199    Returns:
200    - dict: A dictionary containing the following information:
201        - fm (float): The full moon day of 2nd Waso in jdn_mm
202          (jdn+6.5 for MMT) [only valid when watat=1])
203        - watat (int): Intercalary month [1=watat, 0=common].
204
205    Example:
206    >>> calculate_watat(1312)
207    {'fm': 2459372.0, 'watat': 0}
208    """
209    # get data for respective era
210    sy = 1577917828.0 / 4320000.0  # solar year (365.2587565)
211    lm = 1577917828.0 / 53433336.0  # lunar month (29.53058795)
212    mo = 1954168.050623  # beginning of 0 ME for MMT
213    c = get_my_const(my)  # get constants for the corresponding calendar era
214    ta = (sy / 12 - lm) * (12 - c["nm"])  # threshold to adjust
215    ed = (sy * (my + 3739)) % lm  # excess day
216    if ed < ta:
217        ed += lm  # adjust excess days
218    # full moon day of 2nd Waso
219    fm = round(sy * my + mo - ed + 4.5 * lm + c["wo"])
220    tw = 0
221    watat = 0  # find watat
222    if c["ei"] >= 2:
223        # if 2nd era or later find watat based on excess days
224        tw = lm - (sy / 12 - lm) * c["nm"]
225        if ed >= tw:
226            watat = 1
227    else:
228        # if 1st era, find watat by 19 years metonic cycle
229        # Myanmar year is divided by 19 and there is intercalary month
230        # if the remainder is 2,5,7,10,13,15,18
231        # https://github.com/kanasimi/CeJS/blob/master/data/date/calendar.js#L2330
232        watat = (my * 7 + 2) % 19
233        if watat < 0:
234            watat += 19
235        watat = watat // 12
236
237    watat ^= c["ew"]  # correct watat exceptions
238    return {"fm": fm, "watat": watat}
239
240
241def check_year(my):
242    """
243    Calculate the Myanmar calendar information for a given year.
244
245    Parameters:
246    - my (int): Burmese  year.
247
248    Returns:
249    - dict: A dictionary containing the following information:
250        - myt (int): The year type (0=common, 1=little watat, 2=big watat).
251        - tg1 (float): The Julian Day Number for the 1st day of Tagu.
252        - fm (float): The Julian Day Number for the full moon day of the 2nd Waso.
253        - werr (int): Indicator for any watat discrepancy (0=ok, 1=error).
254
255    myt =year type [0=common, 1=little watat, 2=big watat]
256    tg1 = the 1st day of Tagu as jdn_mm (Julian Day Number for MMT)
257    fm = full moon day of [2nd] Waso as Julian Day Number
258    werr= watat discrepancy [0=ok, 1= error] )
259    """
260    yd = 0
261    nd = 0
262    werr = 0
263    fm = 0
264    y2 = calculate_watat(my)
265    y1 = None
266    myt = y2["watat"]
267    while yd < 3:
268        yd += 1
269        y1 = calculate_watat(my - yd)
270        if y1["watat"] == 1:
271            break
272    if myt:
273        nd = (y2["fm"] - y1["fm"]) % 354
274        myt = nd // 31 + 1
275        fm = y2["fm"]
276        if nd not in (30, 31):
277            werr = 1
278    else:
279        fm = y1["fm"] + 354 * yd
280
281    tg1 = y1["fm"] + 354 * yd - 102
282    return {"myt": myt, "tg1": tg1, "fm": fm, "werr": werr}
283
284
285def julian_to_burmese(jdn):
286    """
287    Converts a Julian Day Number to a Burmese date.
288
289    Parameters:
290    - jdn (float): The Julian Day Number to be converted.
291
292    Returns:
293    - dict: A dictionary containing the following information:
294        - myt (int): The year type (0=common, 1=little watat, 2=big watat).
295        - my (int): The Burmese year.
296        - mm (int): The Burmese month.
297        - md (int): The day in the Burmese month.
298
299    Notes:
300    - The function uses the 'cal_my' function to calculate
301      the Burmese year and year type.
302    - The Burmese year is calculated based on the Julian Day
303      Number and the Burmese calendar parameters.
304    - The day count is adjusted based on the Burmese year type and the year length.
305    - The month and day in the Burmese calendar are calculated based on the adjusted day count.
306    - The function returns a dictionary with the calculated Burmese date information.
307    """
308
309    jdn = math.ceil(jdn)  # convert jdn to integer + 0.5
310    sy = 1577917828.0 / 4320000.0  # solar year (365.2587565)
311    mo = 1954168.050623  # beginning of 0 ME
312    my = math.floor((jdn - 0.5 - mo) / sy)  # Burmese year
313    yo = check_year(my)  # check year
314    dd = jdn - yo["tg1"] + 1  # day count
315    b = math.floor(yo["myt"] / 2)
316    c = math.floor(1 / (yo["myt"] + 1))  # big wa and common yr
317    myl = 354 + (1 - c) * 30 + b  # year length
318    mmt = math.floor((dd - 1) / myl)  # month type: late = 1 or early = 0
319    dd -= mmt * myl
320    a = math.floor((dd + 423) / 512)  # adjust day count and threshold
321    mm = math.floor((dd - b * a + c * a * 30 + 29.26) / 29.544)  # month
322    e = math.floor((mm + 12) / 16)
323    f = math.floor((mm + 11) / 16)
324    md = dd - math.floor(29.544 * mm - 29.26) - b * e + c * f * 30  # day
325    mm += f * 3 - e * 4 + 12 * mmt  # adjust month numbers for late months
326    return {
327        "myt": yo["myt"],
328        "my": my,
329        "mm": mm,
330        "md": md,
331    }  # myt = year type , my = year , mm = month , md = day in month
332
333
334def calculate_month_length(mm, myt):
335    """
336    Calculate the length of a month in the Burmese calendar.
337
338    Parameters:
339    - mm (int): month [Tagu=1, Kason=2, Nayon=3,
340          1st Waso=0, (2nd) Waso=4, Wagaung=5,
341          Tawthalin=6, Thadingyut=7, Tazaungmon=8,
342          Nadaw=9, Pyatho=10, Tabodwe=11,
343          Tabaung=12, Late Tagu=13, Late Kason=14 ],
344    - myt (int): year type [0=common, 1=little watat, 2=big watat]
345
346    Returns:
347    - mml (int): The length of the month in days (29 or 30).
348
349    The length of a month in the Burmese calendar is determined
350    based on the month number and the Burmese year
351    type. The month length is calculated as follows:
352    - For months 1, 3, 5, 7, 9, and 11, the length is 30 days.
353    - For months 2, 4, 6, 8, 10, and 12, the length is 29 days.
354    - For the month 3 (Nayon), if the Burmese year type is even,
355      the length is increased by 1 day.
356
357    Example usage:
358    >>> calculate_month_length(1, 0)
359    30
360    >>> calculate_month_length(3, 2)
361    31
362    >>> calculate_month_length(6, 4)
363    29
364    """
365    mml = 30 - (mm % 2)
366    if mm == 3:
367        mml += math.floor(myt / 2)  # adjust if Nayon in big watat
368    # mml = length of the month [29 or 30 days]
369    return mml
370
371
372def calculate_moon_phase(md: int, mm: int, myt: int) -> int:
373    """
374    Calculates the moon phase based on the given day,
375    month, and year type in the Burmese calendar.
376
377    Args:
378        md (int): The day of the month.[1-30]
379        mm (int): The month [Tagu=1, Kason=2, Nayon=3, 1st Waso=0,
380                  (2nd) Waso=4, Wagaung=5, Tawthalin=6, Thadingyut=7,
381                  Tazaungmon=8, Nadaw=9, Pyatho=10, Tabodwe=11, Tabaung=12,
382                  Late Tagu=13, Late Kason=14].
383        myt (int): The year type [0=common, 1=little watat, 2=big watat].
384
385    Returns:
386        int: The moon phase value.
387             mp =moon phase [0=waxing, 1=full moon, 2=waning, 3=new moon]
388    """
389    mml = calculate_month_length(mm, myt)
390    mp = math.floor((md + 1) // 16) + math.floor(md // 16) + \
391        math.floor(md // mml)
392    return mp
393
394
395def calculate_year_length(myt: int) -> int:
396    """
397    Calculates the length of a year in t
398    he Burmese calendar based on a given input.
399
400    Args:
401        myt: [0=common, 1=little watat, 2=big watat].
402
403    Returns:
404        An integer representing the length of the year in
405        the Burmese calendar.
406    """
407    return 354 + (1 - math.floor(1 / (myt + 1))) * 30 + math.floor(myt / 2)
408
409
410def calculate_fortnight_day(md: int) -> int:
411    """
412    Calculates the day of the fortnight based
413    on the given day of the month.
414
415    Args:
416        md (int): The day of the month for which
417                  the fortnight day needs to be calculated.[1-30]
418
419    Returns:
420        int: The day of the fortnight corresponding
421             to the given day of the month.[1 to 15]
422    """
423    fortnights = math.floor(md / 16)
424    fortnight_day = md - 15 * fortnights
425    return fortnight_day
426
427
428def calculate_day_in_month(mf: int, mp: int, mm: int, myt: int) -> int:
429    """
430    Calculates the day in a month in the Burmese calendar
431    based on the given parameters.
432
433    Args:
434        mf (int): [1-15]
435        mp (int): [0=waxing, 1=full moon, 2=waning, 3=new moon]
436        mm (int): The month [Tagu=1, Kason=2, Nayon=3,
437                  1st Waso=0, (2nd) Waso=4, Wagaung=5, Tawthalin=6,
438                  Thadingyut=7, Tazaungmon=8, Nadaw=9, Pyatho=10, Tabodwe=11,
439                  Tabaung=12, Late Tagu=13, Late Kason=14]
440        myt (int): The year type [0=common, 1=little watat, 2=big watat]
441
442    Returns:
443        int: The day in the month [1-30]
444    """
445    mml = calculate_month_length(mm, myt)
446    m1 = mp % 2
447    m2 = mp // 2
448    md = m1 * (15 + m2 * (mml - 15)) + (1 - m1) * (mf + 15 * m2)
449    return md
450
451
452def burmese_to_julian(my: int, mm: int, md: int) -> float:
453    """
454    Converts a date in the Burmese calendar to the Julian Day Number.
455
456    Args:
457        my (int): The Burmese year.
458        mm (int): The Burmese month.
459        md (int): The Burmese day.
460
461    Returns:
462        float: The Julian Day Number corresponding to the given Burmese date.
463    """
464    b = 0
465    c = 0
466    dd = 0
467    myl = 0
468    mmt = 0
469
470    yo = check_year(my)  # check year
471
472    mmt = math.floor(mm // 13)
473    mm = (mm % 13) + mmt  # to 1-12 with month type
474
475    b = math.floor(yo["myt"] // 2)
476    c = 1 - math.floor((yo["myt"] + 1) // 2)  # if big watat and common year
477
478    mm += 4 - math.floor((mm + 15) // 16) * 4 + \
479        ((mm + 12) // 16)  # adjust month
480
481    dd = (
482        md
483        + math.floor(29.544 * mm - 29.26)
484        - c * math.floor((mm + 11) // 16) * 30
485        + b * math.floor((mm + 12) // 16)
486    )
487
488    myl = 354 + (1 - c) * 30 + b
489    dd += mmt * myl  # adjust day count with year length
490
491    return dd + yo["tg1"] - 1
def get_my_const(my: int) -> dict:
 89def get_my_const(my: int) -> dict:
 90    """
 91    ## Return a dictionary of constants based on the given Burmese calendar era.
 92
 93    ### Parameters:
 94    - my (int): The Burmese year to check.
 95
 96    ### Returns:
 97    - dict: A dictionary containing the following constants:
 98        - ei (float): Burmese calendar era ID [1-3]
 99          calculations methods/constants depend on era.
100        - wo (float): Watat offset to compensate.
101        - nm (int): Number of months to find excess days.
102        - ew (int): Exception in watat year.
103
104    ### Notes:
105    - The function uses binary search algorithms (b1_search and b2_search)
106      to find exceptions in the calendar eras.
107    - The constants are determined based on the given Burmese calendar era ID (my).
108    - The function returns a dictionary with the calculated constants.
109
110    ### Dependencies
111        - `burmethon.helper.main.b1_search`
112        - `burmethon.helper.main.b2_search`
113
114    ### Example:
115
116    >>> get_my_const(1312)
117    {'ei': 3, 'wo': -0.5, 'NM': 8, 'ew': 0}
118    """
119    ei = 0
120    wo = 0
121    nm = 0
122    ew = 0
123
124    if my >= 1312:  # The third era (the era after Independence 1312 ME and after)
125        ei = 3
126        wo = -0.5
127        nm = 8
128        fme = [[1377, 1]]
129        wte = [1344, 1345]
130    # The second era (the era under British colony: 1217 ME - 1311 ME)
131    elif my >= 1217:
132        ei = 2
133        wo = -1
134        nm = 4
135        fme = [[1234, 1], [1261, -1]]
136        wte = [1344, 1345]
137    # The first era (the era of Burmese kings: ME1216 and before)
138    elif my >= 1100:
139        # Thandeikta (ME 1100 - 1216)
140        ei = 1.3
141        wo = -0.85
142        nm = -1
143        fme = [[1120, 1], [1126, -1], [1150, 1], [1172, -1], [1207, 1]]
144        wte = [1201, 1202]
145    elif my >= 798:  # Makaranta system 2 (ME 798 - 1099)
146        ei = 1.2
147        wo = -1.1
148        nm = -1
149        fme = [
150            [205, 1],
151            [246, 1],
152            [471, 1],
153            [572, -1],
154            [651, 1],
155            [653, 2],
156            [656, 1],
157            [672, 1],
158            [729, 1],
159            [767, -1],
160        ]
161        wte = []
162    else:  # Makaranta system 1 (ME 0 - 797)
163        ei = 1.1
164        wo = -1.1
165        nm = -1
166        fme = [
167            [205, 1],
168            [246, 1],
169            [471, 1],
170            [572, -1],
171            [651, 1],
172            [653, 2],
173            [656, 1],
174            [672, 1],
175            [729, 1],
176            [767, -1],
177        ]
178        wte = []
179
180    # full moon day offset exceptions
181    i = b2_search(my, fme)
182    if i >= 0:
183        wo += fme[i][1]
184
185    # correct watat exceptions
186    i = b1_search(my, wte)
187    if i >= 0:
188        ew = 1
189
190    return {"ei": ei, "wo": wo, "nm": nm, "ew": ew}

Return a dictionary of constants based on the given Burmese calendar era.

Parameters:

  • my (int): The Burmese year to check.

Returns:

  • dict: A dictionary containing the following constants:
    • ei (float): Burmese calendar era ID [1-3] calculations methods/constants depend on era.
    • wo (float): Watat offset to compensate.
    • nm (int): Number of months to find excess days.
    • ew (int): Exception in watat year.

Notes:

  • The function uses binary search algorithms (b1_search and b2_search) to find exceptions in the calendar eras.
  • The constants are determined based on the given Burmese calendar era ID (my).
  • The function returns a dictionary with the calculated constants.

Dependencies

- `burmethon.helper.main.b1_search`
- `burmethon.helper.main.b2_search`

Example:

>>> get_my_const(1312)
{'ei': 3, 'wo': -0.5, 'NM': 8, 'ew': 0}
def calculate_watat(my):
193def calculate_watat(my):
194    """
195    Check watat (intercalary month).
196
197    Parameters:
198    - my (int): The year to check.
199
200    Returns:
201    - dict: A dictionary containing the following information:
202        - fm (float): The full moon day of 2nd Waso in jdn_mm
203          (jdn+6.5 for MMT) [only valid when watat=1])
204        - watat (int): Intercalary month [1=watat, 0=common].
205
206    Example:
207    >>> calculate_watat(1312)
208    {'fm': 2459372.0, 'watat': 0}
209    """
210    # get data for respective era
211    sy = 1577917828.0 / 4320000.0  # solar year (365.2587565)
212    lm = 1577917828.0 / 53433336.0  # lunar month (29.53058795)
213    mo = 1954168.050623  # beginning of 0 ME for MMT
214    c = get_my_const(my)  # get constants for the corresponding calendar era
215    ta = (sy / 12 - lm) * (12 - c["nm"])  # threshold to adjust
216    ed = (sy * (my + 3739)) % lm  # excess day
217    if ed < ta:
218        ed += lm  # adjust excess days
219    # full moon day of 2nd Waso
220    fm = round(sy * my + mo - ed + 4.5 * lm + c["wo"])
221    tw = 0
222    watat = 0  # find watat
223    if c["ei"] >= 2:
224        # if 2nd era or later find watat based on excess days
225        tw = lm - (sy / 12 - lm) * c["nm"]
226        if ed >= tw:
227            watat = 1
228    else:
229        # if 1st era, find watat by 19 years metonic cycle
230        # Myanmar year is divided by 19 and there is intercalary month
231        # if the remainder is 2,5,7,10,13,15,18
232        # https://github.com/kanasimi/CeJS/blob/master/data/date/calendar.js#L2330
233        watat = (my * 7 + 2) % 19
234        if watat < 0:
235            watat += 19
236        watat = watat // 12
237
238    watat ^= c["ew"]  # correct watat exceptions
239    return {"fm": fm, "watat": watat}

Check watat (intercalary month).

Parameters:

  • my (int): The year to check.

Returns:

  • dict: A dictionary containing the following information:
    • fm (float): The full moon day of 2nd Waso in jdn_mm (jdn+6.5 for MMT) [only valid when watat=1])
    • watat (int): Intercalary month [1=watat, 0=common].

Example:

>>> calculate_watat(1312)
{'fm': 2459372.0, 'watat': 0}
def check_year(my):
242def check_year(my):
243    """
244    Calculate the Myanmar calendar information for a given year.
245
246    Parameters:
247    - my (int): Burmese  year.
248
249    Returns:
250    - dict: A dictionary containing the following information:
251        - myt (int): The year type (0=common, 1=little watat, 2=big watat).
252        - tg1 (float): The Julian Day Number for the 1st day of Tagu.
253        - fm (float): The Julian Day Number for the full moon day of the 2nd Waso.
254        - werr (int): Indicator for any watat discrepancy (0=ok, 1=error).
255
256    myt =year type [0=common, 1=little watat, 2=big watat]
257    tg1 = the 1st day of Tagu as jdn_mm (Julian Day Number for MMT)
258    fm = full moon day of [2nd] Waso as Julian Day Number
259    werr= watat discrepancy [0=ok, 1= error] )
260    """
261    yd = 0
262    nd = 0
263    werr = 0
264    fm = 0
265    y2 = calculate_watat(my)
266    y1 = None
267    myt = y2["watat"]
268    while yd < 3:
269        yd += 1
270        y1 = calculate_watat(my - yd)
271        if y1["watat"] == 1:
272            break
273    if myt:
274        nd = (y2["fm"] - y1["fm"]) % 354
275        myt = nd // 31 + 1
276        fm = y2["fm"]
277        if nd not in (30, 31):
278            werr = 1
279    else:
280        fm = y1["fm"] + 354 * yd
281
282    tg1 = y1["fm"] + 354 * yd - 102
283    return {"myt": myt, "tg1": tg1, "fm": fm, "werr": werr}

Calculate the Myanmar calendar information for a given year.

Parameters:

  • my (int): Burmese year.

Returns:

  • dict: A dictionary containing the following information:
    • myt (int): The year type (0=common, 1=little watat, 2=big watat).
    • tg1 (float): The Julian Day Number for the 1st day of Tagu.
    • fm (float): The Julian Day Number for the full moon day of the 2nd Waso.
    • werr (int): Indicator for any watat discrepancy (0=ok, 1=error).

myt =year type [0=common, 1=little watat, 2=big watat] tg1 = the 1st day of Tagu as jdn_mm (Julian Day Number for MMT) fm = full moon day of [2nd] Waso as Julian Day Number werr= watat discrepancy [0=ok, 1= error] )

def julian_to_burmese(jdn):
286def julian_to_burmese(jdn):
287    """
288    Converts a Julian Day Number to a Burmese date.
289
290    Parameters:
291    - jdn (float): The Julian Day Number to be converted.
292
293    Returns:
294    - dict: A dictionary containing the following information:
295        - myt (int): The year type (0=common, 1=little watat, 2=big watat).
296        - my (int): The Burmese year.
297        - mm (int): The Burmese month.
298        - md (int): The day in the Burmese month.
299
300    Notes:
301    - The function uses the 'cal_my' function to calculate
302      the Burmese year and year type.
303    - The Burmese year is calculated based on the Julian Day
304      Number and the Burmese calendar parameters.
305    - The day count is adjusted based on the Burmese year type and the year length.
306    - The month and day in the Burmese calendar are calculated based on the adjusted day count.
307    - The function returns a dictionary with the calculated Burmese date information.
308    """
309
310    jdn = math.ceil(jdn)  # convert jdn to integer + 0.5
311    sy = 1577917828.0 / 4320000.0  # solar year (365.2587565)
312    mo = 1954168.050623  # beginning of 0 ME
313    my = math.floor((jdn - 0.5 - mo) / sy)  # Burmese year
314    yo = check_year(my)  # check year
315    dd = jdn - yo["tg1"] + 1  # day count
316    b = math.floor(yo["myt"] / 2)
317    c = math.floor(1 / (yo["myt"] + 1))  # big wa and common yr
318    myl = 354 + (1 - c) * 30 + b  # year length
319    mmt = math.floor((dd - 1) / myl)  # month type: late = 1 or early = 0
320    dd -= mmt * myl
321    a = math.floor((dd + 423) / 512)  # adjust day count and threshold
322    mm = math.floor((dd - b * a + c * a * 30 + 29.26) / 29.544)  # month
323    e = math.floor((mm + 12) / 16)
324    f = math.floor((mm + 11) / 16)
325    md = dd - math.floor(29.544 * mm - 29.26) - b * e + c * f * 30  # day
326    mm += f * 3 - e * 4 + 12 * mmt  # adjust month numbers for late months
327    return {
328        "myt": yo["myt"],
329        "my": my,
330        "mm": mm,
331        "md": md,
332    }  # myt = year type , my = year , mm = month , md = day in month

Converts a Julian Day Number to a Burmese date.

Parameters:

  • jdn (float): The Julian Day Number to be converted.

Returns:

  • dict: A dictionary containing the following information:
    • myt (int): The year type (0=common, 1=little watat, 2=big watat).
    • my (int): The Burmese year.
    • mm (int): The Burmese month.
    • md (int): The day in the Burmese month.

Notes:

  • The function uses the 'cal_my' function to calculate the Burmese year and year type.
  • The Burmese year is calculated based on the Julian Day Number and the Burmese calendar parameters.
  • The day count is adjusted based on the Burmese year type and the year length.
  • The month and day in the Burmese calendar are calculated based on the adjusted day count.
  • The function returns a dictionary with the calculated Burmese date information.
def calculate_month_length(mm, myt):
335def calculate_month_length(mm, myt):
336    """
337    Calculate the length of a month in the Burmese calendar.
338
339    Parameters:
340    - mm (int): month [Tagu=1, Kason=2, Nayon=3,
341          1st Waso=0, (2nd) Waso=4, Wagaung=5,
342          Tawthalin=6, Thadingyut=7, Tazaungmon=8,
343          Nadaw=9, Pyatho=10, Tabodwe=11,
344          Tabaung=12, Late Tagu=13, Late Kason=14 ],
345    - myt (int): year type [0=common, 1=little watat, 2=big watat]
346
347    Returns:
348    - mml (int): The length of the month in days (29 or 30).
349
350    The length of a month in the Burmese calendar is determined
351    based on the month number and the Burmese year
352    type. The month length is calculated as follows:
353    - For months 1, 3, 5, 7, 9, and 11, the length is 30 days.
354    - For months 2, 4, 6, 8, 10, and 12, the length is 29 days.
355    - For the month 3 (Nayon), if the Burmese year type is even,
356      the length is increased by 1 day.
357
358    Example usage:
359    >>> calculate_month_length(1, 0)
360    30
361    >>> calculate_month_length(3, 2)
362    31
363    >>> calculate_month_length(6, 4)
364    29
365    """
366    mml = 30 - (mm % 2)
367    if mm == 3:
368        mml += math.floor(myt / 2)  # adjust if Nayon in big watat
369    # mml = length of the month [29 or 30 days]
370    return mml

Calculate the length of a month in the Burmese calendar.

Parameters:

  • mm (int): month [Tagu=1, Kason=2, Nayon=3, 1st Waso=0, (2nd) Waso=4, Wagaung=5, Tawthalin=6, Thadingyut=7, Tazaungmon=8, Nadaw=9, Pyatho=10, Tabodwe=11, Tabaung=12, Late Tagu=13, Late Kason=14 ],
  • myt (int): year type [0=common, 1=little watat, 2=big watat]

Returns:

  • mml (int): The length of the month in days (29 or 30).

The length of a month in the Burmese calendar is determined based on the month number and the Burmese year type. The month length is calculated as follows:

  • For months 1, 3, 5, 7, 9, and 11, the length is 30 days.
  • For months 2, 4, 6, 8, 10, and 12, the length is 29 days.
  • For the month 3 (Nayon), if the Burmese year type is even, the length is increased by 1 day.

Example usage:

>>> calculate_month_length(1, 0)
30
>>> calculate_month_length(3, 2)
31
>>> calculate_month_length(6, 4)
29
def calculate_moon_phase(md: int, mm: int, myt: int) -> int:
373def calculate_moon_phase(md: int, mm: int, myt: int) -> int:
374    """
375    Calculates the moon phase based on the given day,
376    month, and year type in the Burmese calendar.
377
378    Args:
379        md (int): The day of the month.[1-30]
380        mm (int): The month [Tagu=1, Kason=2, Nayon=3, 1st Waso=0,
381                  (2nd) Waso=4, Wagaung=5, Tawthalin=6, Thadingyut=7,
382                  Tazaungmon=8, Nadaw=9, Pyatho=10, Tabodwe=11, Tabaung=12,
383                  Late Tagu=13, Late Kason=14].
384        myt (int): The year type [0=common, 1=little watat, 2=big watat].
385
386    Returns:
387        int: The moon phase value.
388             mp =moon phase [0=waxing, 1=full moon, 2=waning, 3=new moon]
389    """
390    mml = calculate_month_length(mm, myt)
391    mp = math.floor((md + 1) // 16) + math.floor(md // 16) + \
392        math.floor(md // mml)
393    return mp

Calculates the moon phase based on the given day, month, and year type in the Burmese calendar.

Args: md (int): The day of the month.[1-30] mm (int): The month [Tagu=1, Kason=2, Nayon=3, 1st Waso=0, (2nd) Waso=4, Wagaung=5, Tawthalin=6, Thadingyut=7, Tazaungmon=8, Nadaw=9, Pyatho=10, Tabodwe=11, Tabaung=12, Late Tagu=13, Late Kason=14]. myt (int): The year type [0=common, 1=little watat, 2=big watat].

Returns: int: The moon phase value. mp =moon phase [0=waxing, 1=full moon, 2=waning, 3=new moon]

def calculate_year_length(myt: int) -> int:
396def calculate_year_length(myt: int) -> int:
397    """
398    Calculates the length of a year in t
399    he Burmese calendar based on a given input.
400
401    Args:
402        myt: [0=common, 1=little watat, 2=big watat].
403
404    Returns:
405        An integer representing the length of the year in
406        the Burmese calendar.
407    """
408    return 354 + (1 - math.floor(1 / (myt + 1))) * 30 + math.floor(myt / 2)

Calculates the length of a year in t he Burmese calendar based on a given input.

Args: myt: [0=common, 1=little watat, 2=big watat].

Returns: An integer representing the length of the year in the Burmese calendar.

def calculate_fortnight_day(md: int) -> int:
411def calculate_fortnight_day(md: int) -> int:
412    """
413    Calculates the day of the fortnight based
414    on the given day of the month.
415
416    Args:
417        md (int): The day of the month for which
418                  the fortnight day needs to be calculated.[1-30]
419
420    Returns:
421        int: The day of the fortnight corresponding
422             to the given day of the month.[1 to 15]
423    """
424    fortnights = math.floor(md / 16)
425    fortnight_day = md - 15 * fortnights
426    return fortnight_day

Calculates the day of the fortnight based on the given day of the month.

Args: md (int): The day of the month for which the fortnight day needs to be calculated.[1-30]

Returns: int: The day of the fortnight corresponding to the given day of the month.[1 to 15]

def calculate_day_in_month(mf: int, mp: int, mm: int, myt: int) -> int:
429def calculate_day_in_month(mf: int, mp: int, mm: int, myt: int) -> int:
430    """
431    Calculates the day in a month in the Burmese calendar
432    based on the given parameters.
433
434    Args:
435        mf (int): [1-15]
436        mp (int): [0=waxing, 1=full moon, 2=waning, 3=new moon]
437        mm (int): The month [Tagu=1, Kason=2, Nayon=3,
438                  1st Waso=0, (2nd) Waso=4, Wagaung=5, Tawthalin=6,
439                  Thadingyut=7, Tazaungmon=8, Nadaw=9, Pyatho=10, Tabodwe=11,
440                  Tabaung=12, Late Tagu=13, Late Kason=14]
441        myt (int): The year type [0=common, 1=little watat, 2=big watat]
442
443    Returns:
444        int: The day in the month [1-30]
445    """
446    mml = calculate_month_length(mm, myt)
447    m1 = mp % 2
448    m2 = mp // 2
449    md = m1 * (15 + m2 * (mml - 15)) + (1 - m1) * (mf + 15 * m2)
450    return md

Calculates the day in a month in the Burmese calendar based on the given parameters.

Args: mf (int): [1-15] mp (int): [0=waxing, 1=full moon, 2=waning, 3=new moon] mm (int): The month [Tagu=1, Kason=2, Nayon=3, 1st Waso=0, (2nd) Waso=4, Wagaung=5, Tawthalin=6, Thadingyut=7, Tazaungmon=8, Nadaw=9, Pyatho=10, Tabodwe=11, Tabaung=12, Late Tagu=13, Late Kason=14] myt (int): The year type [0=common, 1=little watat, 2=big watat]

Returns: int: The day in the month [1-30]

def burmese_to_julian(my: int, mm: int, md: int) -> float:
453def burmese_to_julian(my: int, mm: int, md: int) -> float:
454    """
455    Converts a date in the Burmese calendar to the Julian Day Number.
456
457    Args:
458        my (int): The Burmese year.
459        mm (int): The Burmese month.
460        md (int): The Burmese day.
461
462    Returns:
463        float: The Julian Day Number corresponding to the given Burmese date.
464    """
465    b = 0
466    c = 0
467    dd = 0
468    myl = 0
469    mmt = 0
470
471    yo = check_year(my)  # check year
472
473    mmt = math.floor(mm // 13)
474    mm = (mm % 13) + mmt  # to 1-12 with month type
475
476    b = math.floor(yo["myt"] // 2)
477    c = 1 - math.floor((yo["myt"] + 1) // 2)  # if big watat and common year
478
479    mm += 4 - math.floor((mm + 15) // 16) * 4 + \
480        ((mm + 12) // 16)  # adjust month
481
482    dd = (
483        md
484        + math.floor(29.544 * mm - 29.26)
485        - c * math.floor((mm + 11) // 16) * 30
486        + b * math.floor((mm + 12) // 16)
487    )
488
489    myl = 354 + (1 - c) * 30 + b
490    dd += mmt * myl  # adjust day count with year length
491
492    return dd + yo["tg1"] - 1

Converts a date in the Burmese calendar to the Julian Day Number.

Args: my (int): The Burmese year. mm (int): The Burmese month. md (int): The Burmese day.

Returns: float: The Julian Day Number corresponding to the given Burmese date.