Pete Haas
Pete Haas

Reputation: 1800

How do I train on time when I already know the date?

I'm looking to filter by a time interval. For example, from 9am to noon. It is unclear how to create that functionality in the training and action concept. For example, I currently have this:

enter image description here

Upvotes: 0

Views: 54

Answers (1)

BixbyDevSupportOne
BixbyDevSupportOne

Reputation: 795

You should train it with DateTimeExpression and use the DateTimeInterval component to get the actual difference Try it this way

action (TestDateTimeInterval) {
  type(Search)
  description (__DESCRIPTION__)
  collect {
    input (dateTimeExpression) {
      type (time.DateTimeExpression)
      min (Optional) max (One)
    }
  }
  output (core.Integer)
}

Action Javascript

module.exports.function = function testDateTimeInterval (dateTimeExpression) {
  var dates = require ('dates')
  var whenStart;
  var whenEnd;
  if (dateTimeExpression.dateTimeInterval) {
    whenStart = dates.ZonedDateTime.of(
      dateTimeExpression.dateTimeInterval.start.date.year,
      dateTimeExpression.dateTimeInterval.start.date.month,
      dateTimeExpression.dateTimeInterval.start.date.day,
      dateTimeExpression.dateTimeInterval.start.time.hour,
      dateTimeExpression.dateTimeInterval.start.time.minute,
      dateTimeExpression.dateTimeInterval.start.time.second);
    whenEnd = dates.ZonedDateTime.of(
      dateTimeExpression.dateTimeInterval.end.date.year,
      dateTimeExpression.dateTimeInterval.end.date.month,
      dateTimeExpression.dateTimeInterval.end.date.day,
      dateTimeExpression.dateTimeInterval.end.time.hour,
      dateTimeExpression.dateTimeInterval.end.time.minute,
      dateTimeExpression.dateTimeInterval.end.time.second);

// If you intend to return the difference between the number of hours
    return dateTimeExpression.dateTimeInterval.end.time.hour - dateTimeExpression.dateTimeInterval.start.time.hour
  }

  return -1;
}

Upvotes: 1

Related Questions