Class datespan

java.lang.Object
types.collections.base.Span<LocalDate>
types.collections.time.datespan
All Implemented Interfaces:
Base, Collection, Time, TimeCollection, TemporalObject

public class datespan extends Span<LocalDate> implements Time, TimeCollection
Class for representing sets of contiguous dates between a lower and an upper bound. The bounds may be inclusive or not.

``DateSpan`` objects can be created with a single argument of type string as in MobilityDB.

>>> DateSpan('(2019-09-08, 2019-09-10)')

Another possibility is to provide the ``lower`` and ``upper`` named
parameters (of type str or date), and optionally indicate whether the
bounds are inclusive or exclusive (by default, the lower bound is inclusive
and the upper is exclusive):
>>> DateSpan(lower='2019-09-08', upper='2019-09-10')
>>> DateSpan(lower='2019-09-08', upper='2019-09-10', lower_inc=False, upper_inc=True)
>>> DateSpan(lower=parse('2019-09-08'), upper=parse('2019-09-10'), upper_inc=True)

Author:
ARIJIT SAMAL
  • Field Details

    • _inner

      private final jnr.ffi.Pointer _inner
  • Constructor Details

    • datespan

      public datespan(jnr.ffi.Pointer inner)
    • datespan

      public datespan(String str)
  • Method Details

    • to_spanset

      Returns a :class:`DateSpanSet` set containing ``self``. Returns: A new :class:`DateSpanSet` instance MEOS Functions: span_to_spanset
      Throws:
      InvocationTargetException
      NoSuchMethodException
      InstantiationException
      IllegalAccessException
    • to_tstzspan

      Returns a :class:`TsTzSpan equivalent to ``self``. Returns: A new :class:`TsTzSpan` instance MEOS Functions: datespan_to_tstzspan
      Throws:
      InvocationTargetException
      NoSuchMethodException
      InstantiationException
      IllegalAccessException
    • duration

      Returns the duration of ``self``. Returns: A :class:`datetime.timedelta` instance representing the duration of the :class:`DateSpan` MEOS Functions: datespan_duration
      Throws:
      InvocationTargetException
      NoSuchMethodException
      InstantiationException
      IllegalAccessException
    • duration_in_days

      public float duration_in_days()
      Returns the duration of ``self``. Returns: Returns a `float` representing the duration of the :class:`DateSpan` in days MEOS Functions: span_width
    • createInner

      public jnr.ffi.Pointer createInner(jnr.ffi.Pointer inner)
      Specified by:
      createInner in class Span<LocalDate>
    • createStringInner

      public jnr.ffi.Pointer createStringInner(String str)
      Specified by:
      createStringInner in class Span<LocalDate>
    • createIntInt

      public jnr.ffi.Pointer createIntInt(Number lower, Number upper, boolean lower_inc, boolean upper_inc)
      Specified by:
      createIntInt in class Span<LocalDate>
    • createIntStr

      public jnr.ffi.Pointer createIntStr(Number lower, String upper, boolean lower_inc, boolean upper_inc)
      Specified by:
      createIntStr in class Span<LocalDate>
    • createStrStr

      public jnr.ffi.Pointer createStrStr(String lower, String upper, boolean lower_inc, boolean upper_inc)
      Specified by:
      createStrStr in class Span<LocalDate>
    • createStrInt

      public jnr.ffi.Pointer createStrInt(String lower, Number upper, boolean lower_inc, boolean upper_inc)
      Specified by:
      createStrInt in class Span<LocalDate>
    • createIntIntNb

      public jnr.ffi.Pointer createIntIntNb(Number lower, Number upper)
      Specified by:
      createIntIntNb in class Span<LocalDate>
    • lower

      public LocalDate lower()
      Description copied from class: Span
      Returns the lower bound of a period
      Specified by:
      lower in class Span<LocalDate>
      Returns:
      T type
    • upper

      public LocalDate upper()
      Description copied from class: Span
      Returns the upper bound of a period
      Specified by:
      upper in class Span<LocalDate>
      Returns:
      T type
    • get_inner

      public jnr.ffi.Pointer get_inner()
      Specified by:
      get_inner in class Span<LocalDate>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • date_adt_to_date

      public LocalDate date_adt_to_date(int ts)
      Function to convert the integer timestamp to LocalDate format so that it can be used by other libraries
    • start_element

      public LocalDate start_element() throws org.locationtech.jts.io.ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException
      Returns the first date in ``self``. Returns: A :class:`date` instance MEOS Functions: dateset_start_value
      Throws:
      org.locationtech.jts.io.ParseException
      InvocationTargetException
      NoSuchMethodException
      InstantiationException
      IllegalAccessException
    • end_element

      public LocalDate end_element() throws org.locationtech.jts.io.ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException
      Returns the last date in ``self``. Returns: A :class:`date` instance MEOS Functions: dateset_end_value
      Throws:
      org.locationtech.jts.io.ParseException
      InvocationTargetException
      NoSuchMethodException
      InstantiationException
      IllegalAccessException
    • scale

      public datespan scale(Integer duration)
      Returns a new :class:`DateSpan` that starts as ``self`` but has duration ``duration``. Examples: >>> DateSpan('[2000-01-01, 2000-01-10]').scale(timedelta(days=2)) >>> 'DateSpan([2000-01-01, 2000-01-03])' Args: duration: :class:`datetime.timedelta` instance representing the duration of the new dateSpan Returns: A new :class:`DateSpan` instance MEOS Functions: datespan_shift_scale
    • shift

      public datespan shift(Integer shift)
      Returns a new :class:`DateSpan` that is the result of shifting ``self`` by ``delta``. Examples: >>> DateSpan('[2000-01-01, 2000-01-10]').shift(timedelta(days=2)) >>> 'DateSpan([2000-01-03, 2000-01-12])' Args: delta: :class:`datetime.timedelta` instance to shift Returns: A new :class:`DateSpan` instance MEOS Functions: datespan_shift_scale
    • shift_scale

      public datespan shift_scale(Integer shift, Integer duration)
      Returns a new :class:`DateSpan` that starts at ``self`` shifted by ``shift`` and has duration ``duration`` Examples: >>> DateSpan('[2000-01-01, 2000-01-10]').shift_scale(shift=timedelta(days=2), duration=timedelta(days=4)) >>> 'DateSpan([2000-01-03, 2000-01-07])' Args: shift: :class:`datetime.timedelta` instance to shift duration: :class:`datetime.timedelta` instance representing the duration of the new dateSpan Returns: A new :class:`DateSpan` instance MEOS Functions: datespan_shift_scale
    • dateToTimestamp

      public int dateToTimestamp(LocalDate date)
      Returns whether ``self`` temporally contains ``content``. Examples: >>> DateSpan('[2012-01-01, 2012-01-04]').contains(DateSpan('[2012-01-02, 2012-01-03]')) >>> True >>> DateSpan('[2012-01-01, 2012-01-02]').contains(DateSpan('(2012-01-01, 2012-01-02)')) >>> True >>> DateSpan('(2012-01-01, 2012-01-02)').contains(DateSpan('[2012-01-01, 2012-01-02]')) >>> False Args: content: temporal object to compare with Returns: True if contains, False otherwise MEOS Functions: contains_span_span, contains_span_spanset, contains_span_date
    • contains

      public boolean contains(Object other) throws Exception
      Throws:
      Exception
    • is_adjacent

      public boolean is_adjacent(Object other) throws Exception
      Returns whether ``self`` is adjacent to ``other``. That is, they share a bound but only one of them contains it. Args: other: object to compare with Returns: True if adjacent, False otherwise MEOS Functions: adjacent_span_span, adjacent_span_spanset, adjacent_span_date
      Throws:
      Exception
    • overlaps

      public boolean overlaps(Object other) throws Exception
      Returns whether ``self`` temporally overlaps ``other``. That is, both share at least an instant Examples: >>> DateSpan('[2012-01-01, 2012-01-02]').overlaps(DateSpan('[2012-01-02, 2012-01-03]')) >>> True >>> DateSpan('[2012-01-01, 2012-01-02)').overlaps(DateSpan('[2012-01-02, 2012-01-03]')) >>> False >>> DateSpan('[2012-01-01, 2012-01-02)').overlaps(DateSpan('(2012-01-02, 2012-01-03]')) >>> False Args: other: temporal object to compare with Returns: True if overlaps, False otherwise MEOS Functions: overlaps_span_span, overlaps_span_spanset
      Throws:
      Exception
    • is_left

      public boolean is_left(Object other) throws Exception
      Returns whether ``self`` is strictly before ``other``. That is, ``self`` ends before ``other`` starts. Examples: >>> DateSpan('[2012-01-01, 2012-01-02)').is_left(DateSpan('[2012-01-02, 2012-01-03]')) >>> True >>> DateSpan('[2012-01-01, 2012-01-02)').is_left(DateSpan('(2012-01-02, 2012-01-03]')) >>> True >>> DateSpan('[2012-01-01, 2012-01-02]').is_left(DateSpan('[2012-01-02, 2012-01-03]')) >>> False Args: other: temporal object to compare with Returns: True if before, False otherwise MEOS Functions: left_span_span, left_span_spanset, before_span_date,
      Throws:
      Exception
    • is_over_or_left

      public boolean is_over_or_left(Object other) throws Exception
      Returns whether ``self`` is before ``other`` allowing overlap. That is, ``self`` ends before ``other`` ends (or at the same time). Examples: >>> DateSpan('[2012-01-01, 2012-01-02)').is_over_or_left(DateSpan('[2012-01-02, 2012-01-03]')) >>> True >>> DateSpan('[2012-01-01, 2012-01-02]').is_over_or_left(DateSpan('[2012-01-02, 2012-01-03]')) >>> True >>> DateSpan('[2012-01-03, 2012-01-05]').is_over_or_left(DateSpan('[2012-01-01, 2012-01-04]')) >>> False Args: other: temporal object to compare with Returns: True if before, False otherwise MEOS Functions: overleft_span_span, overleft_span_spanset, overbefore_span_date,
      Throws:
      Exception
    • is_over_or_right

      public boolean is_over_or_right(Object other) throws Exception
      Returns whether ``self`` is after ``other`` allowing overlap. That is, ``self`` starts after ``other`` starts (or at the same time). Examples: >>> DateSet('{2012-01-02, 2012-01-03}').is_over_or_right(DateSpan('[2012-01-01, 2012-01-02)')) >>> True >>> DateSet('{2012-01-02, 2012-01-03}').is_over_or_right(DateSpan('[2012-01-01, 2012-01-02]')) >>> True >>> DateSet('{2012-01-02, 2012-01-03}').is_over_or_right(DateSpan('[2012-01-01, 2012-01-03]')) >>> False Args: other: temporal object to compare with Returns: True if overlapping or after, False otherwise MEOS Functions: overafter_set_date, overright_span_span, overright_span_spanset
      Throws:
      Exception
    • is_right

      public boolean is_right(Object other) throws Exception
      Returns whether ``self`` is strictly after ``other``. That is, ``self`` starts after ``other`` ends. Examples: >>> DateSpan('[2012-01-02, 2012-01-03]').is_right(DateSpan('[2012-01-01, 2012-01-02)')) >>> True >>> DateSpan('(2012-01-02, 2012-01-03]').is_right(DateSpan('[2012-01-01, 2012-01-02)')) >>> True >>> DateSpan('[2012-01-02, 2012-01-03]').is_right(DateSpan('[2012-01-01, 2012-01-02]')) >>> False Args: other: temporal object to compare with Returns: True if after, False otherwise MEOS Functions: right_span_span, right_span_spanset, after_span_date,
      Throws:
      Exception
    • is_before

      public boolean is_before(Object other) throws Exception
      Specified by:
      is_before in interface TimeCollection
      Throws:
      Exception
    • is_over_or_before

      public boolean is_over_or_before(Object other) throws Exception
      Specified by:
      is_over_or_before in interface TimeCollection
      Throws:
      Exception
    • is_over_or_after

      public boolean is_over_or_after(Object other) throws Exception
      Specified by:
      is_over_or_after in interface TimeCollection
      Throws:
      Exception
    • is_after

      public boolean is_after(Object other) throws Exception
      Specified by:
      is_after in interface TimeCollection
      Throws:
      Exception
    • distance

      public Duration distance(Object other) throws Exception
      Returns the temporal distance between ``self`` and ``other``. Args: other: temporal object to compare with Returns: A :class:`datetime.timedelta` instance MEOS Functions: distance_set_date, distance_dateset_dateset, distance_datespanset_datespan, distance_datespanset_datespanset
      Throws:
      Exception
    • timestampToLocalDateTime

      public static LocalDateTime timestampToLocalDateTime(int timestamp)
      Convert timestamp (number of seconds since epoch) to LocalDateTime
    • intersection

      public LocalDateTime intersection(Object other) throws Exception
      Returns the temporal intersection of ``self`` and ``other``. Args: other: temporal object to intersect with Returns: A :class:`TimeDate` instance. The actual class depends on ``other``. MEOS Functions: intersection_set_date, intersection_set_set, intersection_spanset_span, intersection_spanset_spanset
      Throws:
      Exception
    • minus

      public datespanset minus(Object other) throws Exception
      Returns the temporal difference of ``self`` and ``other``. Args: other: temporal object to diff with Returns: A :class:`DateSpanSet` instance. MEOS Functions: minus_span_date, minus_span_spanset, minus_span_span
      Throws:
      Exception
    • timestampToLocalDate

      public static LocalDate timestampToLocalDate(int timestamp)
      Convert timestamp (number of seconds since epoch) to LocalDate
    • subtract_from

      public LocalDate subtract_from(Object other) throws Exception
      Throws:
      Exception
    • union

      public datespanset union(Object other) throws Exception
      Returns the temporal union of ``self`` and ``other``. Args: other: temporal object to merge with Returns: A :class:`DateSpanSet` instance. MEOS Functions: union_span_date, union_spanset_span, union_span_span
      Throws:
      Exception