@@ -229,12 +229,38 @@ <h5>Plot / Export data</h5>
229229 } ) ;
230230 }
231231
232+ function getDateYearWeek ( date ) {
233+ const currentDate =
234+ ( typeof date === 'object' ) ? date : new Date ( ) ;
235+ const januaryFirst =
236+ new Date ( currentDate . getFullYear ( ) , 0 , 1 ) ;
237+ const daysToNextMonday =
238+ ( januaryFirst . getDay ( ) === 1 ) ? 0 :
239+ ( 7 - januaryFirst . getDay ( ) ) % 7 ;
240+ const nextMonday =
241+ new Date ( currentDate . getFullYear ( ) , 0 ,
242+ januaryFirst . getDate ( ) + daysToNextMonday ) ;
243+
244+ var weekNumber = ( currentDate < nextMonday ) ? 52 :
245+ ( currentDate > nextMonday ? Math . ceil (
246+ ( currentDate - nextMonday ) / ( 24 * 3600 * 1000 ) / 7 ) : 1 ) ;
247+
248+ if ( weekNumber < 10 ) {
249+ weekNumber = `0${ weekNumber } ` ;
250+ }
251+
252+ const year = currentDate . getFullYear ( )
253+
254+ return `${ year } ${ weekNumber } ` ;
255+ }
256+
232257 function submitMode ( event ) {
233258 event . preventDefault ( ) ;
234259
235260 var dataSource = document . getElementById ( 'source' ) . value ;
236261 var dataSignal = document . getElementById ( 'signal' ) . value ;
237262 var geographicType = document . getElementById ( 'geographic_type' ) . value ;
263+ var timeType = "{{ signal.time_type }}" ;
238264 // geographicValue is a comma separated string of geographic values. type can be string or integer
239265 // in case of string, it should be converted to lowercase
240266 // else it will be treated as integer
@@ -247,14 +273,19 @@ <h5>Plot / Export data</h5>
247273
248274 if ( currentMode === 'epivis' ) {
249275 var epiVisUrl = "{{ epivis_url }}" ;
250- var urlParamsEncoded = btoa ( `{"datasets":[{"color":"#415742","title":"value","params":{"_endpoint":"covidcast","data_source":"${ dataSource } ","signal":"${ dataSignal } ","time_type":"day ","geo_type":"${ geographicType } ","geo_value":"${ geographicValue } "}}]}` ) ;
276+ var urlParamsEncoded = btoa ( `{"datasets":[{"color":"#415742","title":"value","params":{"_endpoint":"covidcast","data_source":"${ dataSource } ","signal":"${ dataSignal } ","time_type":"${ timeType } ","geo_type":"${ geographicType } ","geo_value":"${ geographicValue } "}}]}` ) ;
251277
252278 epiVisUrl += `#${ urlParamsEncoded } ` ;
253279 window . open ( epiVisUrl , '_blank' ) . focus ( ) ;
254280 } else if ( currentMode === 'export' ) {
255281 var startDate = document . getElementById ( 'start_date' ) . value ;
256282 var endDate = document . getElementById ( 'end_date' ) . value ;
257283
284+ if ( timeType === "week" ) {
285+ startDate = getDateYearWeek ( new Date ( startDate ) ) ;
286+ endDate = getDateYearWeek ( new Date ( endDate ) ) ;
287+ } ;
288+
258289 var dataExportUrl = "{{ data_export_url }}" ;
259290
260291 if ( startDate === '' || endDate === '' ) {
@@ -268,8 +299,13 @@ <h5>Plot / Export data</h5>
268299 } else {
269300 var timeType = document . getElementById ( 'time_type' ) . value ;
270301
271- var startDate = document . getElementById ( 'start_date' ) . value . replaceAll ( '-' , '' ) ;
272- var endDate = document . getElementById ( 'end_date' ) . value . replaceAll ( '-' , '' ) ;
302+ var startDate = document . getElementById ( 'start_date' ) . value ;
303+ var endDate = document . getElementById ( 'end_date' ) . value ;
304+
305+ if ( timeType === "week" ) {
306+ startDate = getDateYearWeek ( new Date ( startDate ) ) ;
307+ endDate = getDateYearWeek ( new Date ( endDate ) ) ;
308+ } ;
273309
274310 var requestSent = false ;
275311
0 commit comments