Reputation: 47
created_at
is the value I Want to compare with the beginDate
and the endDate
.
var newARRA = chain(this.props.transferts.transfertAccount)
.filter({ 'officeSender':
this.props.users.user.office,officeReceiver:this.state.selectedOffice,
'created_at':(this.state.beginDate,this.state.endDate)})
.groupBy("currency")
.map((v, k) => ({
currency: k,
amount: sumBy(v, 'fee')
}))
.value();
Upvotes: 2
Views: 4653
Reputation: 236
I would prefer using a date library. > date-fns could do this for you
var isWithinRange = require('date-fns/is_within_range')
isWithinRange(
new Date(2014, 0, 3), new Date(2014, 0, 1), new Date(2014, 0, 7)
)//=> true
Upvotes: 1
Reputation: 191976
You'll need to use the filter's predicate function. Example (not tested):
var newARRA = chain(this.props.transferts.transfertAccount)
.filter(({ officeSender, officeReceiver, created_at }) => {
return _.eq(officeSender, this.props.users.user.office) &&
_.eq(officeReceiver, this.state.selectedOffice) &&
_.gte(created_at, this.state.beginDate) &&
_.lte(created_at, this.state.endDate) &&
})
.groupBy("currency")
.map((v, k) => ({
currency: k,
amount: sumBy(v, 'fee')
}))
.value();
Upvotes: 3
Reputation: 5957
You could use the moment library to achieve this for you, assuming that the two values are moment like dates:
'created_at': moment().isBetween(this.state.beginDate, this.state.endDate)
This does assume that the dates are moment-like and don't require any pre-processing by the moment library.
Upvotes: 0