+ /**
+ * @param WebRequest $request
+ * @return string
+ */
+ private function getTimestampFromRequest( WebRequest $request ) {
+ // Backwards compatibility checks for URIs with only year and/or month.
+ $year = $request->getInt( 'year' );
+ $month = $request->getInt( 'month' );
+ $day = null;
+ if ( $year !== 0 || $month !== 0 ) {
+ if ( $year === 0 ) {
+ $year = MWTimestamp::getLocalInstance()->format( 'Y' );
+ }
+ if ( $month < 1 || $month > 12 ) {
+ // month is invalid so treat as December (all months)
+ $month = 12;
+ }
+ // month is valid so check day
+ $day = cal_days_in_month( CAL_GREGORIAN, $month, $year );
+
+ // Left pad the months and days
+ $month = str_pad( $month, 2, "0", STR_PAD_LEFT );
+ $day = str_pad( $day, 2, "0", STR_PAD_LEFT );
+ }
+
+ $before = $request->getVal( 'date-range-to' );
+ if ( $before ) {
+ $parts = explode( '-', $before );
+ $year = $parts[0];
+ // check date input is valid
+ if ( count( $parts ) === 3 ) {
+ $month = $parts[1];
+ $day = $parts[2];
+ }
+ }
+ return $year && $month && $day ? $year . '-' . $month . '-' . $day : '';
+ }