Permalink
Browse files

Fix date sorting in various screens

  • Loading branch information...
1 parent 1328279 commit 03cc42c702c3b2d1fc6c60e5e153fa8040c5196d @richard-julien richard-julien committed Jan 11, 2017
@@ -2,7 +2,7 @@ import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import {Link} from 'react-router'
import R from 'ramda'
-import {dateFormat} from '../../utils/Time'
+import {dateFormat, timeDiff} from '../../utils/Time'
import {fetchExercises} from '../../actions/Exercise'
import * as Constants from '../../constants/ComponentTypes'
import {AppBar} from '../../components/AppBar'
@@ -87,7 +87,7 @@ class IndexAuthenticated extends Component {
const sortExercises = (exercises) => {
let exercisesSorting = R.pipe(
- R.sort((a, b) => a.exercise_start_date > b.exercise_start_date)
+ R.sort((a, b) => timeDiff(a.exercise_start_date, b.exercise_start_date))
)
return exercisesSorting(exercises)
}
@@ -6,7 +6,7 @@ import * as Constants from '../../../constants/ComponentTypes'
import Theme from '../../../components/Theme'
import {T} from '../../../components/I18n'
import {i18nRegister} from '../../../utils/Messages'
-import {dateFormat} from '../../../utils/Time'
+import {dateFormat, timeDiff} from '../../../utils/Time'
import {List} from '../../../components/List'
import {Dialog} from '../../../components/Dialog'
import {MainListItem, SecondaryListItem, TertiaryListItem, MainSmallListItem} from '../../../components/list/ListItem'
@@ -385,7 +385,7 @@ class IndexExercise extends Component {
const injects = R.pipe(
R.map(data => R.pathOr({}, ['injects', data.inject_id], this.props)),
- R.sort((a, b) => a.inject_date > b.inject_date)
+ R.sort((a, b) => timeDiff(a.inject_date, b.inject_date))
)(incident_injects)
let nestedItems2 = injects.map(inject => {
@@ -3,6 +3,7 @@ import {connect} from 'react-redux'
import R from 'ramda'
import {T} from '../../../../components/I18n'
import {i18nRegister} from '../../../../utils/Messages'
+import {timeDiff} from '../../../../utils/Time'
import * as Constants from '../../../../constants/ComponentTypes'
import {fetchUsers} from '../../../../actions/User'
import {fetchOrganizations} from '../../../../actions/Organization'
@@ -308,7 +309,7 @@ const filterComchecks = (comchecks, audienceId) => {
let comchecksFilterAndSorting = R.pipe(
R.values,
R.filter(n => n.comcheck_audience.audience_id === audienceId && !n.comcheck_finished),
- R.sort((a, b) => a.comcheck_end_date > b.comcheck_end_date)
+ R.sort((a, b) => timeDiff(a.comcheck_end_date, b.comcheck_end_date))
)
return comchecksFilterAndSorting(comchecks)
}
@@ -2,7 +2,7 @@ import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import R from 'ramda'
import Rx from 'rxjs/Rx'
-import {FIVE_SECONDS} from '../../../../utils/Time'
+import {FIVE_SECONDS, timeDiff} from '../../../../utils/Time'
import {i18nRegister} from '../../../../utils/Messages'
import {T} from '../../../../components/I18n'
import {dateFormat} from '../../../../utils/Time'
@@ -281,7 +281,7 @@ const filterDryinjectsPending = (dryinjects, dryrunId) => {
let dryinjectsFilterAndSorting = R.pipe(
R.values,
R.filter(n => n.dryinject_dryrun.dryrun_id === dryrunId && n.dryinject_status.status_name === 'PENDING'),
- R.sort((a, b) => a.dryinject_date > b.dryinject_date)
+ R.sort((a, b) => timeDiff(a.dryinject_date, b.dryinject_date))
)
return dryinjectsFilterAndSorting(dryinjects)
}
@@ -1,7 +1,7 @@
import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import Rx from 'rxjs/Rx'
-import {FIVE_SECONDS} from '../../../../utils/Time'
+import {FIVE_SECONDS, timeDiff} from '../../../../utils/Time'
import R from 'ramda'
import {i18nRegister} from '../../../../utils/Messages'
import {dateFormat} from '../../../../utils/Time'
@@ -307,7 +307,7 @@ const filterInjectsPending = (state, ownProps) => {
const exerciseId = ownProps.params.exerciseId
let injectsFilterAndSorting = R.pipe(
R.values,
- R.sort((a, b) => a.inject_date > b.inject_date),
+ R.sort((a, b) => timeDiff(a.inject_date, b.inject_date)),
R.filter(n => n.inject_exercise === exerciseId && n.inject_status.status_name === 'PENDING')
)
return injectsFilterAndSorting(injects)
View
@@ -9,35 +9,39 @@ export const ONE_MINUTE = 60 * 1000
export const FIVE_SECONDS = 5000
export const ONE_SECOND = 1000
+export const parse = (date) => {
+ return moment(date)
+}
+
+export const now = () => {
+ return moment()
+}
+
export const dayFormat = (data) => {
- return data ? moment(data).format(dayDateFormat) : "-"
+ return data ? parse(data).format(dayDateFormat) : "-"
+}
+
+export const timeDiff = (start, end) => {
+ return parse(start).diff(parse(end))
}
export const timeFormat = (data) => {
- return data ? moment(data).format(timeDateFormat) : "-"
+ return data ? parse(data).format(timeDateFormat) : "-"
}
export const dateFormat = (data, specificFormat) => {
- return data ? moment(data).format(specificFormat ? specificFormat : openexDateFormat) : "-"
+ return data ? parse(data).format(specificFormat ? specificFormat : openexDateFormat) : "-"
}
export const dateToISO = (date) => {
- var momentDate = moment(date, openexDateFormat, true)
+ var momentDate = parse(date, openexDateFormat, true)
return momentDate.isValid() ? momentDate.format() : 'invalid-date'
}
-export const parse = (date) => {
- return moment(date)
-}
-
-export const now = () => {
- return moment()
-}
-
export const dateFromNow = (dateString) => {
- return dateString ? countdown(moment(dateString).toDate()).toString() : "-"
+ return dateString ? countdown(parse(dateString).toDate()).toString() : "-"
}
export const logDate = () => {
- return moment().format('HH:mm:ss.SSS')
+ return now().format('HH:mm:ss.SSS')
}

0 comments on commit 03cc42c

Please sign in to comment.