本文整理汇总了Python中WRCCUtils.format_date_string方法的典型用法代码示例。如果您正苦于以下问题:Python WRCCUtils.format_date_string方法的具体用法?Python WRCCUtils.format_date_string怎么用?Python WRCCUtils.format_date_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WRCCUtils
的用法示例。
在下文中一共展示了WRCCUtils.format_date_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_end_date
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import format_date_string [as 别名]
#.........这里部分代码省略.........
return err
else:
return '%s is not a valid Start Date for a multi-station or grid request!' %str(form['end_date'])
s_date = WRCCUtils.date_to_eight(s_date)
e_date = WRCCUtils.date_to_eight(e_date)
if len(e_date)!=8:
return '%s is not a valid date.' %str(form['end_date'])
try:
int(e_date)
except:
return '%s is not a valid date.' %str(form['end_date'])
#Check month
if int(e_date[4:6]) < 1 or int(e_date[4:6]) > 12:
return '%s is not a valid date.' %str(form['end_date'])
#Check day
if int(e_date[6:8]) < 1 or int(e_date[4:6]) > 31:
return '%s is not a valid date.' %str(form['end_date'])
#Ceck for month length
ml = WRCCData.MONTH_LENGTHS[int(e_date[4:6]) - 1]
if int(e_date[6:8]) > ml:
if str(e_date[4:6]) == '02' or str(e_date[4:6]) == '2':
if int(e_date[6:8]) == 29 and WRCCUtils.is_leap_year(e_date[0:4]):
return None
#return '%s only has %s days. You entered: %s' %(WRCCData.NUMBER_TO_MONTH_NAME[str(e_date[4:6])],'29',str(e_date[6:8]))
else:
return '%s only has %s days. You entered: %s' %(WRCCData.NUMBER_TO_MONTH_NAME[str(e_date[4:6])],str(ml),str(e_date[6:8]))
else:
return '%s only has %s days. You entered: %s' %(WRCCData.NUMBER_TO_MONTH_NAME[str(e_date[4:6])],str(ml),str(e_date[6:8]))
#Check that start date is ealier than end date
if s_date.lower() == 'por':
return err
try:
sd = datetime.datetime(int(s_date[0:4]), int(s_date[4:6].lstrip('0')), int(s_date[6:8].lstrip('0')))
except:
pass
try:
ed = datetime.datetime(int(e_date[0:4]), int(e_date[4:6].lstrip('0')), int(e_date[6:8].lstrip('0')))
except:
return '%s is not a valid date.' %form['end_date']
try:
if ed < sd:
return 'Start Date is later then End Year.'
except:pass
#Check grid data dates
if 'location' in form.keys() or ('data_type' in form.keys() and form['data_type'] == 'grid'):
flag = False
#Set grid date range
#Set grid date range
if int(form['grid']) in range(22,42):
grid_dr = [['19500101','20991231']]
else:
grid_dr = WRCCData.GRID_CHOICES[str(form['grid'])][3]
#For Prism we need to check if monthy/yearly resolution
#and pick proper daterange
if 'temporal_resolution' in form.keys() and form['temporal_resolution'] in ['mly','yly'] and str(form['grid']) == '21':
grid_dr = WRCCData.PRISM_MLY_YLY[str(form['grid'])][3]
for dr in grid_dr:
grid_s = WRCCUtils.date_to_datetime(dr[0])
grid_e = WRCCUtils.date_to_datetime(dr[1])
if grid_s <= sd and ed <= grid_e:
flag = False
break
else:
if str(dr[1]) == str(grid_dr[-1][1]):
flag = True
continue
if flag:
grid_s = WRCCUtils.datetime_to_date(grid_s,'-')
grid_e = WRCCUtils.datetime_to_date(grid_e,'-')
return 'Valid date range for this grid is: ' + grid_s + ' - ' + grid_e
'''
#Limit grid requests to max 10 years for multi point requests
if not 'location' in form.keys() and (ed - sd).days > 10 * 366:
err = 'Request for more than one grid point are limited to ten years or less! ' +\
'Please adjust your dates accordingly.'
return err
'''
#Check for unreasonable start and end dates
#for station data requests
data_type = WRCCUtils.get_data_type(form)
unreasonable = False
if data_type == 'station' and form['app_name'] == 'multi_lister':
#Limit multi station requests to 75 years
if not 'station_id' in form.keys() and (ed - sd).days > 75 * 366:
err = 'Request for more than one station are limited to 75 years or less! ' +\
'Please adjust your dates accordingly.'
#Check that station data end date is today or earlier
if 'station_id' in form.keys() or ('data_type' in form.keys() and form['data_type'] == 'station'):
if e_date.lower() != 'por':
today = WRCCUtils.format_date_string(WRCCUtils.set_back_date(0),'-')
if WRCCUtils.date_to_datetime(e_date) > WRCCUtils.date_to_datetime(today):
return 'Not a valid End Date. Date should be ' + today +' or ealier.'
return err
示例2: set_initial
# 需要导入模块: import WRCCUtils [as 别名]
# 或者: from WRCCUtils import format_date_string [as 别名]
#.........这里部分代码省略.........
initial['start_year'] = Get('start_year','POR')
initial['end_year'] = Get('end_year','POR')
initial['start_month'] = Get('start_month', '1')
initial['start_day'] = Get('start_day', '1')
initial['min_year_fut'] = sd_fut[0:4]
initial['max_year_fut'] = ed_fut[0:4]
if app_name == 'seasonal_summary':
initial['min_year'] = Get('min_year',sd[0:4])
initial['max_year'] = Get('max_year', ed[0:4])
initial['end_month'] = Get('end_month', '1')
initial['end_day'] = Get('end_day', '31')
if app_name in ['intraannual']:
if initial['start_year'].lower() != 'por':
initial['min_year'] = initial['start_year']
else:
initial['min_year'] = Get('min_year',sd[0:4])
if initial['end_year'].lower() != 'por':
initial['max_year'] = initial['end_year']
else:
initial['max_year'] = Get('max_year', ed[0:4])
#Plotting vars
initial['show_climatology'] = Get('show_climatology','F')
initial['show_percentile_5'] = Get('show_percentile_5','F')
initial['show_percentile_10'] = Get('show_percentile_10','F')
initial['show_percentile_25'] = Get('show_percentile_25','F')
initial['target_year'] = Get('target_year_figure', None)
if initial['target_year'] is None:
initial['target_year'] = Get('target_year_form',initial['min_year'])
if initial['element'] in ['pcpn','snow','evap','pet']:
initial['calculation'] = Get('calculation','cumulative')
else:
initial['calculation'] = Get('calculation','values')
else:
initial['start_date'] = Get('start_date', WRCCUtils.format_date_string(fourtnight,'-'))
initial['end_date'] = Get('end_date', WRCCUtils.format_date_string(yesterday,'-'))
#data windows and flags
sw = '01-01'; ew = '01-31'
if 'start_date' in initial.keys() and 'end_date' in initial.keys():
if initial['start_date'] and initial['end_date']:
sw, ew = WRCCUtils.set_start_end_window(initial['start_date'],initial['end_date'])
if app_name in ['single_lister', 'multi_lister','map_overlay']:
initial['start_window'] = Get('start_window', sw)
initial['end_window'] = Get('end_window',ew)
initial['temporal_resolution'] = Get('temporal_resolution','dly')
initial['show_flags'] = Get('show_flags', 'F')
initial['show_observation_time'] = Get('show_observation_time', 'F')
if app_name in ['station_finder']:
initial['start_window'] = Get('start_window', sw)
initial['end_window'] = Get('end_window',ew)
#data summaries
if app_name in ['monthly_spatial_summary','temporal_summary', 'seasonal_summary']:
initial['data_summary'] = Get('data_summary', 'temporal_summary')
elif app_name in ['spatial_summary','multi_lister','map_overlay']:
initial['data_summary'] = Get('data_summary', 'spatial_summary')
else:
initial['data_summary'] = Get('data_summary', 'none')
if app_name in ['temporal_summary', 'monthly_spatial_summary','seasonal_summary', 'sf_download']:
if 'element' in initial.keys() and initial['element'] in ['pcpn','snow','evap','pet']:
initial['temporal_summary'] = Get('temporal_summary', 'sum')
else:
initial['temporal_summary'] = Get('temporal_summary', 'mean')
else:
initial['temporal_summary'] = Get('temporal_summary', 'mean')
if app_name in ['single_lister', 'multi_lister','spatial_summary','sf_download','map_overlay']:
initial['spatial_summary'] = Get('spatial_summary', 'mean')