CDaysBetween.java

  1. /*
  2.  * @cond LICENSE
  3.  * ######################################################################################
  4.  * # LGPL License                                                                       #
  5.  * #                                                                                    #
  6.  * # This file is part of the LightJason AgentSpeak(L++)                                #
  7.  * # Copyright (c) 2015-19, LightJason (info@lightjason.org)                            #
  8.  * # This program is free software: you can redistribute it and/or modify               #
  9.  * # it under the terms of the GNU Lesser General Public License as                     #
  10.  * # published by the Free Software Foundation, either version 3 of the                 #
  11.  * # License, or (at your option) any later version.                                    #
  12.  * #                                                                                    #
  13.  * # This program is distributed in the hope that it will be useful,                    #
  14.  * # but WITHOUT ANY WARRANTY; without even the implied warranty of                     #
  15.  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                      #
  16.  * # GNU Lesser General Public License for more details.                                #
  17.  * #                                                                                    #
  18.  * # You should have received a copy of the GNU Lesser General Public License           #
  19.  * # along with this program. If not, see http://www.gnu.org/licenses/                  #
  20.  * ######################################################################################
  21.  * @endcond
  22.  */

  23. package org.lightjason.agentspeak.action.builtin.datetime;

  24. import org.joda.time.Days;
  25. import org.joda.time.Instant;

  26. import javax.annotation.Nonnull;
  27. import java.util.List;
  28. import java.util.stream.Stream;



  29. /**
  30.  * returns the days between two dates.
  31.  * The actions returns the number of days between
  32.  * two date-time objects, the action never
  33.  * fails. A positive value will be returned iif the
  34.  * first date-time item is before the second one, a
  35.  * negative value will be returned iif the first
  36.  * date-time item is after the second date-time item
  37.  *
  38.  * {@code [D1|D2] = datetime/daysbetween( DateTime1, DateTime2, DateTime3, DateTime4 );}
  39.  */
  40. public final class CDaysBetween extends IBetween
  41. {
  42.     /**
  43.      * serial id
  44.      */
  45.     private static final long serialVersionUID = 2204654538944733054L;

  46.     @Nonnull
  47.     @Override
  48.     protected final Stream<?> apply( @Nonnull final Stream<List<Instant>> p_datetime )
  49.     {
  50.         return p_datetime
  51.                 .map( i -> Days.daysBetween( i.get( 0 ), i.get( 1 ) ) )
  52.                 .mapToDouble( Days::getDays )
  53.                 .boxed();
  54.     }

  55. }