Created
October 16, 2023 09:01
-
-
Save ehzawad/ec656e5e42b9efe9f8c45a65a255c6af to your computer and use it in GitHub Desktop.
calender_to_bangla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
import calendar | |
class BengaliMonths(Enum): | |
January = 'জানুয়ারী' | |
February = 'ফেব্রুয়ারী' | |
March = 'মার্চ' | |
April = 'এপ্রিল' | |
May = 'মে' | |
June = 'জুন' | |
July = 'জুলাই' | |
August = 'আগস্ট' | |
September = 'সেপ্টেম্বর' | |
October = 'অক্টোবর' | |
November = 'নভেম্বর' | |
December = 'ডিসেম্বর' | |
bengali_numbers = { | |
1: 'এক', | |
2: 'দুই', | |
3: 'তিন', | |
4: 'চার', | |
5: 'পাঁচ', | |
6: 'ছয়', | |
7: 'সাত', | |
8: 'আট', | |
9: 'নয়', | |
10: 'দশ', | |
11: 'এগারো', | |
12: 'বারো', | |
13: 'তেরো', | |
14: 'চোদ্দো', | |
15: 'পনেরো', | |
16: 'ষোলো', | |
17: 'সতেরো', | |
18: 'আঠারো', | |
19: 'ঊনিশ', | |
20: 'বিশ', | |
21: 'একুশ', | |
22: 'বাইশ', | |
23: 'তেইশ', | |
24: 'চুরাশ', | |
25: 'পঁচাশ', | |
26: 'ছাব্বিশ', | |
27: 'সাতাশ', | |
28: 'আটাশ', | |
29: 'ঊনত্রিশ', | |
30: 'ত্রিশ', | |
31: 'একত্রিশ' | |
} | |
def convert_to_bengali_date(date, separator='-'): | |
day, month, year = date.split(separator) | |
# Mapping integer month to its English name, then to its Bengali counterpart | |
month_name_english = calendar.month_name[int(month)] | |
bengali_date = f"{bengali_numbers[int(day)]} {BengaliMonths[month_name_english].value} {year} সাল" | |
return bengali_date | |
if __name__ == "__main__": | |
date1 = "02-10-2020" | |
date2 = "02/10/2020" | |
date3 = "02 10 2020" | |
bn_date1 = convert_to_bengali_date(date1) | |
bn_date2 = convert_to_bengali_date(date2, separator='/') | |
bn_date3 = convert_to_bengali_date(date3, separator=' ') | |
print(bn_date1) | |
print(bn_date2) | |
print(bn_date3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment