Exemple #1
0
 def _compute_yday_wday_if_necessary(self):
     if not self.__have_yday_wday:
         njtm = self.__jtm.copy()
         jalali_update(njtm)
         self.__jtm.tm_wday = njtm.tm_wday
         self.__jtm.tm_yday = njtm.tm_yday
         self.__have_yday_wday = True
Exemple #2
0
 def timetuple(self):
     """Return a :class:`time.struct_time` from this date.  DST flag is
     -1"""
     njtm = self.__jtm.copy()
     jalali_update(njtm)
     njtm.tm_isdst = -1
     return jtm_to_struct_time(njtm)
Exemple #3
0
 def timetuple(self):
     """Return a :class:`time.struct_time` from this date.  DST flag is
     -1"""
     njtm = self.__jtm.copy()
     jalali_update(njtm)
     njtm.tm_isdst = -1
     return jtm_to_struct_time(njtm)
Exemple #4
0
 def _compute_yday_wday_if_necessary(self):
     if not self.__have_yday_wday:
         njtm = self.__jtm.copy()
         jalali_update(njtm)
         self.__jtm.tm_wday = njtm.tm_wday
         self.__jtm.tm_yday = njtm.tm_yday
         self.__have_yday_wday = True
Exemple #5
0
def gregorian_from_jalali(date_or_datetime):
    """
    Make Gregorian :class:`python:datetime.datetime` from Jalali
    :class:`.datetime` or make Gregorian :class:`python:datetime.date` from
    Jalali :class:`.date`.

    >>> gregorian_from_jalali(datetime(1392, 9, 2, 23, 10, 2))
    datetime.datetime(2013, 11, 23, 23, 10, 2)
    >>> gregorian_from_jalali(datetime(1392, 6, 30, 22, 30))
    datetime.datetime(2013, 9, 21, 22, 30)
    >>> gregorian_from_jalali(date(1392, 6, 30))
    datetime.date(2013, 9, 21)
    """
    if isinstance(date_or_datetime, datetime):
        jdate = date_or_datetime.date()
        time = date_or_datetime.timetz()
    elif isinstance(date_or_datetime, date):
        jdate = date_or_datetime
        time = None
    else:
        raise TypeError('Expected Jalali %s or %s instance, not %s' %
                        (datetime.__name__, date.__name__,
                         date_or_datetime.__class__.__name__))
    if jdate < date(1348, 10, 11):
        raise ValueError("Can't convert dates before Epoch")
    # to stop dst changes from bugging conversion, just convert date
    njtm = jdate.jtm.copy()
    jalali_update(njtm)  # pragma: jmktime needs yday TODO: remove
    gdate = _std_dt_mod.date.fromtimestamp(jmktime(njtm))
    if time is None:
        return gdate
    return _std_dt_mod.datetime.combine(gdate, time)
Exemple #6
0
 def utctimetuple(self):
     if self.tzinfo is None:
         d = self
     else:
         d = self.replace(tzinfo=None) - self.utcoffset()
     njtm = d.jtm.copy()
     jalali_update(njtm)
     return jtm_to_struct_time(njtm)
Exemple #7
0
 def utctimetuple(self):
     if self.tzinfo is None:
         d = self
     else:
         d = self.replace(tzinfo=None) - self.utcoffset()
     njtm = d.jtm.copy()
     jalali_update(njtm)
     return jtm_to_struct_time(njtm)
Exemple #8
0
def _normalized_date(year, mon, mday):
    """For internal testing only.  For actual normalization call jalali_update
    or normalize_jtm.
    0 <= mon < 12
    1 <= mday < 32
    """
    jtm = struct_jtm()
    jtm.tm_year = year
    jtm.tm_mon = mon
    jtm.tm_mday = mday
    jalali_update(jtm)
    return jtm.tm_year, jtm.tm_mon, jtm.tm_mday
Exemple #9
0
    def ctime(self):
        """Return a string representing the date and time.

        >>> datetime(1392, 9, 1, 12, 32, 14, 992).ctime()
        'Fri Aza 01 12:32:14 1392'
        """
        # TODO:
        # this should be enough if jmktime fixed:
        # return jctime(jmktime(self.__jtm))
        njtm = self.__jtm.copy()
        jalali_update(njtm)
        return jctime(jmktime(njtm))
Exemple #10
0
    def timetuple(self):
        """Return a :class:`time.struct_time` from this date. The tm_isdst
        flag of the result is set according to the dst() method: tzinfo is
        None or dst() returns None, tm_isdst is set to -1; else if dst()
        returns a non-zero value, tm_isdst is set to 1; else tm_isdst is set
        to 0."""

        njtm = self.__jtm.copy()
        jalali_update(njtm)
        if self.dst() is None:
            njtm.tm_isdst = -1
        elif self.dst() == 0:
            njtm.tm_isdst = 0
        else:
            njtm.tm_isdst = 1
        return jtm_to_struct_time(njtm)
Exemple #11
0
    def timetuple(self):
        """Return a :class:`time.struct_time` from this date. The tm_isdst
        flag of the result is set according to the dst() method: tzinfo is
        None or dst() returns None, tm_isdst is set to -1; else if dst()
        returns a non-zero value, tm_isdst is set to 1; else tm_isdst is set
        to 0."""

        njtm = self.__jtm.copy()
        jalali_update(njtm)
        if self.dst() is None:
            njtm.tm_isdst = -1
        elif self.dst() == 0:
            njtm.tm_isdst = 0
        else:
            njtm.tm_isdst = 1
        return jtm_to_struct_time(njtm)
Exemple #12
0
def normalize_jtm(jtm, microsecond=0):
    jtm.tm_sec, microsecond = normalized_pair(jtm.tm_sec, microsecond, 1000000)
    jalali_update(jtm)
    return microsecond
Exemple #13
0
 def ctime(self):
     """Return a string representing the date, ``date(1392, 8, 2).ctime() ==
     'Thu Aba 02 00:00:00 1392'``"""
     njtm = self.__jtm.copy()
     jalali_update(njtm)
     return jctime(jmktime(njtm))