def parse(cls, report, objects, data, localcontext):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = datetime.now()
localcontext['print_date'] = datetime.astimezone(dt.replace(
tzinfo=pytz.utc), timezone)
localcontext['print_time'] = localcontext['print_date'].time()
return super(PatientEvaluationReport, cls).parse(report, objects, data,
localcontext)
python类astimezone()的实例源码
patient_evaluation_report.py 文件源码
项目:health-mosconi
作者: GNUHealth-Mosconi
项目源码
文件源码
阅读 33
收藏 0
点赞 0
评论 0
def parse(cls, report, objects, data, localcontext):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = datetime.now()
localcontext['print_date'] = datetime.astimezone(dt.replace(
tzinfo=pytz.utc), timezone)
localcontext['print_time'] = localcontext['print_date'].time()
return super(PatientEvaluationReport, cls).parse(report, objects, data,
localcontext)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def get_report_start_date(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_start
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).date()
def get_report_start_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_start
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def get_report_end_date(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_end
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).date()
def get_report_end_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_end
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def get_report_prescription_date(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.prescription_date
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).date()
def get_report_prescription_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.prescription_date
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def get_report_evaluation_date(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_start
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).date()
def get_report_evaluation_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_start
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def get_print_date():
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = datetime.now()
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone)
def get_report_surgery_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.surgery_date
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
tzinfo.py 文件源码
项目:amazon-alexa-twilio-customer-service
作者: ameerbadri
项目源码
文件源码
阅读 34
收藏 0
点赞 0
评论 0
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime.
This is normally a no-op, as StaticTzInfo timezones never have
ambiguous cases to correct:
>>> from pytz import timezone
>>> gmt = timezone('GMT')
>>> isinstance(gmt, StaticTzInfo)
True
>>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt)
>>> gmt.normalize(dt) is dt
True
The supported method of converting between timezones is to use
datetime.astimezone(). Currently normalize() also works:
>>> la = timezone('America/Los_Angeles')
>>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
>>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
>>> gmt.normalize(dt).strftime(fmt)
'2011-05-07 08:02:03 GMT (+0000)'
'''
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
def get_report_start_date(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_start
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).date()
def get_report_start_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_start
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def get_report_end_date(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_end
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).date()
def get_report_end_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_end
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def get_report_prescription_time(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.prescription_date
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).time()
def get_report_evaluation_date(self, name):
Company = Pool().get('company.company')
timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)
dt = self.evaluation_start
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone).date()