<s> """<STR_LIT>""" <EOL> import re <EOL> import time <EOL> import calendar <EOL> from django . utils . dates import MONTHS , MONTHS_3 , MONTHS_AP , WEEKDAYS , WEEKDAYS_ABBR <EOL> from django . utils . tzinfo import LocalTimezone <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . encoding import force_unicode <EOL> re_formatchars = re . compile ( r'<STR_LIT>' ) <EOL> re_escaped = re . compile ( r'<STR_LIT>' ) <EOL> class Formatter ( object ) : <EOL> def format ( self , formatstr ) : <EOL> pieces = [ ] <EOL> for i , piece in enumerate ( re_formatchars . split ( force_unicode ( formatstr ) ) ) : <EOL> if i % <NUM_LIT:2> : <EOL> pieces . append ( force_unicode ( getattr ( self , piece ) ( ) ) ) <EOL> elif piece : <EOL> pieces . append ( re_escaped . sub ( r'<STR_LIT>' , piece ) ) <EOL> return u'<STR_LIT>' . join ( pieces ) <EOL> class TimeFormat ( Formatter ) : <EOL> def __init__ ( self , t ) : <EOL> self . data = t <EOL> def a ( self ) : <EOL> "<STR_LIT>" <EOL> if self . data . hour > <NUM_LIT:11> : <EOL> return _ ( '<STR_LIT>' ) <EOL> return _ ( '<STR_LIT>' ) <EOL> def A ( self ) : <EOL> "<STR_LIT>" <EOL> if self . data . hour > <NUM_LIT:11> : <EOL> return _ ( '<STR_LIT>' ) <EOL> return _ ( '<STR_LIT>' ) <EOL> def B ( self ) : <EOL> "<STR_LIT>" <EOL> raise NotImplementedError <EOL> def f ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . data . minute == <NUM_LIT:0> : <EOL> return self . g ( ) <EOL> return u'<STR_LIT>' % ( self . g ( ) , self . i ( ) ) <EOL> def g ( self ) : <EOL> "<STR_LIT>" <EOL> if self . data . hour == <NUM_LIT:0> : <EOL> return <NUM_LIT:12> <EOL> if self . data . hour > <NUM_LIT:12> : <EOL> return self . data . hour - <NUM_LIT:12> <EOL> return self . data . hour <EOL> def G ( self ) : <EOL> "<STR_LIT>" <EOL> return self . data . hour <EOL> def h ( self ) : <EOL> "<STR_LIT>" <EOL> return u'<STR_LIT>' % self . g ( ) <EOL> def H ( self ) : <EOL> "<STR_LIT>" <EOL> return u'<STR_LIT>' % self . G ( ) <EOL> def i ( self ) : <EOL> "<STR_LIT>" <EOL> return u'<STR_LIT>' % self . data . minute <EOL> def P ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . data . minute == <NUM_LIT:0> and self . data . hour == <NUM_LIT:0> : <EOL> return _ ( '<STR_LIT>' ) <EOL> if self . data . minute == <NUM_LIT:0> and self . data . hour == <NUM_LIT:12> : <EOL> return _ ( '<STR_LIT>' ) <EOL> return u'<STR_LIT>' % ( self . f ( ) , self . a ( ) ) <EOL> def s ( self ) : <EOL> "<STR_LIT>" <EOL> return u'<STR_LIT>' % self . data . second <EOL> def u ( self ) : <EOL> "<STR_LIT>" <EOL> return self . data . microsecond <EOL> class DateFormat ( TimeFormat ) : <EOL> year_days = [ None , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> def __init__ ( self , dt ) : <EOL> self . data = dt <EOL> self . timezone = getattr ( dt , '<STR_LIT>' , None ) <EOL> if hasattr ( self . data , '<STR_LIT>' ) and not self . timezone : <EOL> self . timezone = LocalTimezone ( dt ) <EOL> def b ( self ) : <EOL> "<STR_LIT>" <EOL> return MONTHS_3 [ self . data . month ] <EOL> def c ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . data . isoformat ( ) <EOL> def d ( self ) : <EOL> "<STR_LIT>" <EOL> return u'<STR_LIT>' % self . data . day <EOL> def D ( self ) : <EOL> "<STR_LIT>" <EOL> return WEEKDAYS_ABBR [ self . data . weekday ( ) ] <EOL> def F ( self ) : <EOL> "<STR_LIT>" <EOL> return MONTHS [ self . data . month ] <EOL> def I ( self ) : <EOL> "<STR_LIT>" <EOL> if self . timezone and self . timezone . dst ( self . data ) : <EOL> return u'<STR_LIT:1>' <EOL> else : <EOL> return u'<STR_LIT:0>' <EOL> def j ( self ) : <EOL> "<STR_LIT>" <EOL> return self . data . day <EOL> def l ( self ) : <EOL> "<STR_LIT>" <EOL> return WEEKDAYS [ self . data . weekday ( ) ] <EOL> def L ( self ) : <EOL> "<STR_LIT>" <EOL> return calendar . isleap ( self . data . year ) <EOL> def m ( self ) : <EOL> "<STR_LIT>" <EOL> return u'<STR_LIT>' % self . data . month <EOL> def M ( self ) : <EOL> "<STR_LIT>" <EOL> return MONTHS_3 [ self . data . month ] . title ( ) <EOL> def n ( self ) : <EOL> "<STR_LIT>" <EOL> return self . data . month <EOL> def N ( self ) : <EOL> "<STR_LIT>" <EOL> return MONTHS_AP [ self . data . month ] <EOL> def O ( self ) : <EOL> "<STR_LIT>" <EOL> seconds = self . Z ( ) <EOL> return u"<STR_LIT>" % ( seconds // <NUM_LIT> , ( seconds // <NUM_LIT> ) % <NUM_LIT> ) <EOL> def r ( self ) : <EOL> "<STR_LIT>" <EOL> return self . format ( '<STR_LIT>' ) <EOL> def S ( self ) : <EOL> "<STR_LIT>" <EOL> if self . data . day in ( <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> ) : <EOL> return u'<STR_LIT>' <EOL> last = self . data . day % <NUM_LIT:10> <EOL> if last == <NUM_LIT:1> : <EOL> return u'<STR_LIT>' <EOL> if last == <NUM_LIT:2> : <EOL> return u'<STR_LIT>' <EOL> if last == <NUM_LIT:3> : <EOL> return u'<STR_LIT>' <EOL> return u'<STR_LIT>' <EOL> def t ( self ) : <EOL> "<STR_LIT>" <EOL> return u'<STR_LIT>' % calendar . monthrange ( self . data . year , self . data . month ) [ <NUM_LIT:1> ] <EOL> def T ( self ) : <EOL> "<STR_LIT>" <EOL> name = self . timezone and self . timezone . tzname ( self . data ) or None <EOL> if name is None : <EOL> name = self . format ( '<STR_LIT:O>' ) <EOL> return unicode ( name ) <EOL> def U ( self ) : <EOL> "<STR_LIT>" <EOL> if getattr ( self . data , '<STR_LIT>' , None ) : <EOL> return int ( calendar . timegm ( self . data . utctimetuple ( ) ) ) <EOL> else : <EOL> return int ( time . mktime ( self . data . timetuple ( ) ) ) <EOL> def w ( self ) : <EOL> "<STR_LIT>" <EOL> return ( self . data . weekday ( ) + <NUM_LIT:1> ) % <NUM_LIT:7> <EOL> def W ( self ) : <EOL> "<STR_LIT>" <EOL> week_number = None <EOL> jan1_weekday = self . data . replace ( month = <NUM_LIT:1> , day = <NUM_LIT:1> ) . weekday ( ) + <NUM_LIT:1> <EOL> weekday = self . data . weekday ( ) + <NUM_LIT:1> <EOL> day_of_year = self . z ( ) <EOL> if day_of_year <= ( <NUM_LIT:8> - jan1_weekday ) and jan1_weekday > <NUM_LIT:4> : <EOL> if jan1_weekday == <NUM_LIT:5> or ( jan1_weekday == <NUM_LIT:6> and calendar . isleap ( self . data . year - <NUM_LIT:1> ) ) : <EOL> week_number = <NUM_LIT> <EOL> else : <EOL> week_number = <NUM_LIT> <EOL> else : <EOL> if calendar . isleap ( self . data . year ) : <EOL> i = <NUM_LIT> <EOL> else : <EOL> i = <NUM_LIT> <EOL> if ( i - day_of_year ) < ( <NUM_LIT:4> - weekday ) : <EOL> week_number = <NUM_LIT:1> <EOL> else : <EOL> j = day_of_year + ( <NUM_LIT:7> - weekday ) + ( jan1_weekday - <NUM_LIT:1> ) <EOL> week_number = j // <NUM_LIT:7> <EOL> if jan1_weekday > <NUM_LIT:4> : <EOL> week_number -= <NUM_LIT:1> <EOL> return week_number <EOL> def y ( self ) : <EOL> "<STR_LIT>" <EOL> return unicode ( self . data . year ) [ <NUM_LIT:2> : ] <EOL> def Y ( self ) : <EOL> "<STR_LIT>" <EOL> return self . data . year <EOL> def z ( self ) : <EOL> "<STR_LIT>" <EOL> doy = self . year_days [ self . data . month ] + self . data . day <EOL> if self . L ( ) and self . data . month > <NUM_LIT:2> : <EOL> doy += <NUM_LIT:1> <EOL> return doy <EOL> def Z ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . timezone : <EOL> return <NUM_LIT:0> <EOL> offset = self . timezone . utcoffset ( self . data ) <EOL> return offset . days * <NUM_LIT> + offset . seconds <EOL> def format ( value , format_string ) : <EOL> "<STR_LIT>" <EOL> df = DateFormat ( value ) <EOL> return df . format ( format_string ) <EOL> def time_format ( value , format_string ) : <EOL> "<STR_LIT>" <EOL> tf = TimeFormat ( value ) <EOL> return tf . format ( format_string ) </s>
