• File: datetimeutil.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/paste/util/__pycache__/datetimeutil.cpython-37.pyc
  • Date Modified: 12/01/2019 7:09 PM
  • File size: 7.79 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

bN+
@sdZddlmZmZmZddlmZddlZddddd	d
gZddZd
dZ	ddZ
ddZddZeddZ
dddddddddddddZdd Zd!d"d!d#d!d#d!d!d#d!d#d!d$Zd%d&d'd(d)d*d+d,d-d.d/d0d$Zd1Zd2d	Zd5d4d
ZdS)6a.	
Date, Time, and Timespan Parsing Utilities

This module contains parsing support to create "human friendly"
``datetime`` object parsing.  The explicit goal of these routines is
to provide a multi-format date/time support not unlike that found in
Microsoft Excel.  In most approaches, the input is very "strict" to
prevent errors -- however, this approach is much more liberal since we
are assuming the user-interface is parroting back the normalized value
and thus the user has immediate feedback if the data is not typed in
correctly.

  ``parse_date`` and ``normalize_date``

     These functions take a value like '9 jan 2007' and returns either an
     ``date`` object, or an ISO 8601 formatted date value such
     as '2007-01-09'.  There is an option to provide an Oracle database
     style output as well, ``09 JAN 2007``, but this is not the default.

     This module always treats '/' delimiters as using US date order
     (since the author's clients are US based), hence '1/9/2007' is
     January 9th.  Since this module treats the '-' as following
     European order this supports both modes of data-entry; together
     with immediate parroting back the result to the screen, the author
     has found this approach to work well in pratice.

  ``parse_time`` and ``normalize_time``

     These functions take a value like '1 pm' and returns either an
     ``time`` object, or an ISO 8601 formatted 24h clock time
     such as '13:00'.  There is an option to provide for US style time
     values, '1:00 PM', however this is not the default.

  ``parse_datetime`` and ``normalize_datetime``

     These functions take a value like '9 jan 2007 at 1 pm' and returns
     either an ``datetime`` object, or an ISO 8601 formatted
     return (without the T) such as '2007-01-09 13:00'. There is an
     option to provide for Oracle / US style, '09 JAN 2007 @ 1:00 PM',
     however this is not the default.

  ``parse_delta`` and ``normalize_delta``

     These functions take a value like '1h 15m' and returns either an
     ``timedelta`` object, or an 2-decimal fixed-point
     numerical value in hours, such as '1.25'.  The rationale is to
     support meeting or time-billing lengths, not to be an accurate
     representation in mili-seconds.  As such not all valid
     ``timedelta`` values will have a normalized representation.

)	timedeltatimedate)	localtimeNparse_timedeltanormalize_timedelta
parse_timenormalize_time
parse_datenormalize_datecCsy
t|SdSdS)N)stringatoi)valrH/opt/alt/python37/lib/python3.7/site-packages/paste/util/datetimeutil.py_number@s
rcCs|sdSt|}d|kr:t|}tt|d|ddSd|kpHd|k}d|kpXd|k}d|k}xd	D]}t||d
}qhWt|}t|}d}d}||rt|	}|rt|	}t
|dkr|st|	}t||dS)
z1
    returns a ``timedelta`` object, or None
    N.<g?)hoursminutesh:mzminu:teshour() gr)rlowerfloatrintreplacestripsplitreversepoplen)rZfHourZfMinZ	fFractionnoisehrmirrrrIs.



cCsHt|tkrt|}|sdS|jd}|jdd}d||ddfS)z
    produces a normalized string value of the timedelta

    This module returns a normalized time span value consisting of the
    number of hours in fractional form. For example '1h 15min' is
    formatted as 01.25.
    irz%d.%02dd)typestrrseconds)rr$Zmnrrrres
cCsr|sdSd}}t|}dt|dk}dt|dk}xdD]}t||d}q@Wt|}t|dkrt|d}t|d}n|d}t|dkrnd|krt}|d	}|d
}n|d|krd}nnt|d	krt|}|s|s|d
kr|d7}n@t|dkr(t|dd}t|dd}nt|dd}|rP|dkrP|d}|rh|dkrh|d}t||S)Nrapz:amp.rnowZnoon)	rrfindrrr"rrr)rr$r%ZamflagZpmflagr#tmrrrrxsD




cCs||sdSt|tkrt|}|s0d|j|jfS|j}d}|dksJ|dkrPd}n|dkrld}|dkrl|d}d||j|fS)	Nr&z	%02d:%02dZAMr.r2ZPMz%02d:%02d %s)r(r)rhourminute)valueZampmr$amrrrr	sr.)daysr0r1r4r3	
r2)janfebmaraprmayjunjulaugsepoctnovdeccCs2x tD]\}}||kr
|Sq
Wtd|dS)Nzunknown month '%s')_str2numitems	TypeError)rkeymonrrr_monthsrU)r.r>r0r1r4r?r3r@rArBrCr2JanFebMarAprMayJunJulAugSepOctNovDec)rTtuewedthufrisatsunc	Cs|sdSt|}d}|d}t|dkr|\}}}d|krL|dd}d|krb|dd}y,tt|t|t|}d|dd}Wntk
rYnX|s|dd}|dkrt}n@|tkrt}t	t
|d	}x||kr|t7}qW|r||dd
}|dd
dd}xD|D]8}	yt|	}
Wntk
rbYnX|t|
d7}q<W|Sd}}}
xd
D]}t||d}qWxtD]}t||d}qWg}d}d}xZ|D]R}|r|r|s|dd}}n|r|dd}d}||qWtd|}dt|kr"t|d}t|d	}t|d}t|ddkr|}|r|}|}
nt|d	}|}
nx|dkr|}t|ddkrtd|r|}
|}n|}
t|d	}n.|}
|}t|ddkrtdt|d}ndt|krt|d}t|d	}|dkrx|}d	}
|dkrj|}nt|d	}nl|dkr|dkr|}|}d	}
n$|dkr|}|}
n|}
t|d	}n$|dkr|}d	}
n|}
t|d}nd	t|kr|d}|st|}|dk	rd	}
nt|}t|}dt|krnt|dd}t|dd}t|dd}
n`t|dkr|dkr|}d	}d	}
n t|dd}t|dd}
n|dkr|}
ntdt}|dkr|d	}|
dkr|d}
|dkr
|d}t|||
S)N-r0+rrZxxxrB)r/Ztodr.z +z -)r=)/rk,*FTr&r>r1zfour digit year requiredir@r?)r0r1ir5 )rrrr"rr
ValueErrortoday_wkdylistindex
isoweekday_one_dayrrrisdigitappendjoinrrUrRr)r)rr/strictyrdZchkidxtailitemr=ZyrmoZdyr#outlastZldigchr,bcvr7rrrr
s


























TcCsL|sdSt|tkrt|}|r4d|j|j|jfSd|jt|j|jfS)Nr&z
%4d-%02d-%02dz%02d %s %4d)r(r)r
yearmonthday_num2str)rZiso8601rrrrbs)T)__doc__datetimerrrrr__all__rrrrr	rwrPrUZ_days_in_monthrrsr
rrrrr<module>7s.	&