khayyam icon indicating copy to clipboard operation
khayyam copied to clipboard

incompelete timetuple.

Open Mahyar24 opened this issue 4 years ago • 0 comments

the default datetime module return timetuple with hour, minute, and second but what JalaliDatetime.timetuple() returns doesn't have these three items, so sadly in my case I should make my timetuple manually, I know that it's not a big deal but I think maybe it's the best that your excellent library behaves just like datetime. for my use, I need to have timetuple with date and time of Tehran timezone on a foreign server for logging my logs into our Persian paradigm. (if it's help!)

from khayyam import JalaliDatetime
from time import struct_time
from pytz import timezone

def tehrantime(*args, **kwargs):
    tehran_dt = JalaliDatetime.now(tz=timezone('Asia/Tehran'))
    time_tuple = struct_time((tehran_dt.year, tehran_dt.month, tehran_dt.day, tehran_dt.hour, tehran_dt.minute, 
                              tehran_dt.second, tehran_dt.weekday(), tehran_dt.dayofyear(), 1))
    return time_tuple

Thanks BTW.

Mahyar24 avatar Apr 06 '20 10:04 Mahyar24