-
Notifications
You must be signed in to change notification settings - Fork 212
Fix issue #212 #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #212 #272
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,29 @@ import './style.scss'; | |
const CHALLENGE_PLACEHOLDER_COUNT = 8; | ||
|
||
export default function ChallengeListing(props) { | ||
function CheckDateTime(str) { | ||
const reg = /^(\d{4})-(\d{1,2})-(\d{1,2})T(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{3})Z$/; | ||
const r = str.match(reg); | ||
if (r == null) return false; | ||
r[2] -= 1; | ||
const d = new Date(r[1], r[2], r[3], r[4], r[5], r[6]); | ||
if (d.getFullYear() !== r[1]) return false; | ||
if (d.getMonth() !== r[2]) return false; | ||
if (d.getDate() !== r[3]) return false; | ||
if (d.getHours() !== r[4]) return false; | ||
if (d.getMinutes() !== r[5]) return false; | ||
if (d.getSeconds() !== r[6]) return false; | ||
return true; | ||
} | ||
const filterState = props.filterState; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @twicoder And, although it probably will do the trick, the best way to make the check and avoid using the date in filter, if it is invalid, is inside reducer (the filter query params are picked up from URL during server-side rendering, thus checking it there will guarantee that invalid dates won't be used anywhere): https://github.com/topcoder-platform/community-app/blob/develop/src/shared/reducers/challenge-listing/index.js#L272 Also, once at the client-side, we should remove invalid dates from query. This can be done at this point. To update query params use this utility function: https://github.com/topcoder-platform/community-app/blob/develop/src/shared/utils/url.js#L20 |
||
if (filterState) { | ||
if (!!filterState.startDate && CheckDateTime(filterState.startDate) === false) { | ||
delete filterState.startDate; | ||
} | ||
if (!!filterState.endDate && CheckDateTime(filterState.endDate) === false) { | ||
delete filterState.endDate; | ||
} | ||
} | ||
let challenges = props.challenges; | ||
|
||
if (props.communityFilter) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twicoder Ha! Love your efforts here, and most probably, this code behaves properly (have not tested), but I believe, the best way to do this check is actually just using
momentjs
, doingmoment(date).isValid()
: https://momentjs.com/docs/#/parsing/is-valid/