class VirtualDate

Defined in:

virtualdate.cr

Constant Summary

VERSION = [VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION].join('.')
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_REVISION = 2

Instance Method Summary

Instance Method Detail

def begin : VirtualTime::TimeOrVirtualTime | Nil #

Absolute begin date/time. Item is never "on" before this date.


[View source]
def begin=(begin __arg0 : VirtualTime::TimeOrVirtualTime | Nil) #

Absolute begin date/time. Item is never "on" before this date.


[View source]
def due : Array(VirtualTime) #

List of VirtualTimes on which the item is "on"/due/active.


[View source]
def due=(due : Array(VirtualTime)) #

List of VirtualTimes on which the item is "on"/due/active.


[View source]
def due_on?(time : VirtualTime::TimeOrVirtualTime = Time.local, times = @due) #

Checks if item is due on any of its date and time specifications.


[View source]
def due_on_any_date?(time : VirtualTime::TimeOrVirtualTime = Time.local, times = @due) #

Checks if item is due on any of its date specifications (without times).


[View source]
def due_on_any_time?(time : VirtualTime::TimeOrVirtualTime = Time.local, times = @due) #

Checks if item is due on any of its time specifications (without dates).


[View source]
def end : VirtualTime::TimeOrVirtualTime | Nil #

Absolute end date/time. Item is never "on" after this date.


[View source]
def end=(end __arg0 : VirtualTime::TimeOrVirtualTime | Nil) #

Absolute end date/time. Item is never "on" after this date.


[View source]
def matches_any_date?(time : VirtualTime::TimeOrVirtualTime, times, default) #

Checks if any item in times matches the date part of time


[View source]
def matches_any_time?(time : VirtualTime::TimeOrVirtualTime, times, default) #

Checks if any item in times matches the time part of time


[View source]
def max_shift : Time::Span | Nil #

Max amount of total time by which item can be shifted, before it's considered unschedulable (false) E.g., if a company has meetings every 7 days, it probably makes no sense to reschedule a particular meeting for more than 6 days later, since on the 7th day a new meeting would be scheduled anyway.


[View source]
def max_shift=(max_shift : Time::Span | Nil) #

Max amount of total time by which item can be shifted, before it's considered unschedulable (false) E.g., if a company has meetings every 7 days, it probably makes no sense to reschedule a particular meeting for more than 6 days later, since on the 7th day a new meeting would be scheduled anyway.


[View source]
def max_shifts : Int32 #

Max amount of shift attempts, before it's considered unschedulable (false)

If shift = 1.minute and max_shifts = 1440, it means the item will be shifted at most 1440 minutes (1 day) compared to the original time for which it was asked, and on which it was unschedulable due to omit times.


[View source]
def max_shifts=(max_shifts : Int32) #

Max amount of shift attempts, before it's considered unschedulable (false)

If shift = 1.minute and max_shifts = 1440, it means the item will be shifted at most 1440 minutes (1 day) compared to the original time for which it was asked, and on which it was unschedulable due to omit times.


[View source]
def omit : Array(VirtualTime) #

List of VirtualTimes on which the item should be "omitted", i.e. on which it should not be on/due/active. For example, this list may include weekends, known holidays in a year, sick days, vacation days, etc.

Maybe this list should also implicitly contain all already scheduled items?


[View source]
def omit=(omit : Array(VirtualTime)) #

List of VirtualTimes on which the item should be "omitted", i.e. on which it should not be on/due/active. For example, this list may include weekends, known holidays in a year, sick days, vacation days, etc.

Maybe this list should also implicitly contain all already scheduled items?


[View source]
def omit_on?(time : VirtualTime::TimeOrVirtualTime = Time.local, times = @omit) #

Checks if item is omitted on any of its date and time specifications.


[View source]
def omit_on_dates?(time : VirtualTime::TimeOrVirtualTime = Time.local, times = @omit) #

Checks if item is omitted on any of its date specifications (without times).


[View source]
def omit_on_times?(time : VirtualTime::TimeOrVirtualTime = Time.local, times = @omit) #

Checks if item is omitted on any of its time specifications (without dates).


[View source]
def on : Nil | Bool | Time::Span #

Fixed value of #on? for this item. This is useful for outright setting the item's status, without any calculations.

It can be used for things such as:

  • Marking an item as parmanently on, e.g. after it has once been activated
  • Marking an item as permanently off, if it was disabled until further notice
  • Marking the item as always shifted/postponed by certain time (e.g. to keep it on the 'upcoming' list or something)

This field has the same union of types as #shift.

The default is nil (no setting), to not override anything and allow for the standard calculations to run. If defined, this setting takes precedence over #begin and #end.


[View source]
def on=(on : Nil | Bool | Time::Span) #

Fixed value of #on? for this item. This is useful for outright setting the item's status, without any calculations.

It can be used for things such as:

  • Marking an item as parmanently on, e.g. after it has once been activated
  • Marking an item as permanently off, if it was disabled until further notice
  • Marking the item as always shifted/postponed by certain time (e.g. to keep it on the 'upcoming' list or something)

This field has the same union of types as #shift.

The default is nil (no setting), to not override anything and allow for the standard calculations to run. If defined, this setting takes precedence over #begin and #end.


[View source]
def on?(time : VirtualTime::TimeOrVirtualTime = Time.local, *, max_shift = @max_shift, max_shifts = @max_shifts, hint = time.is_a?(Time) ? time : Time.local) #

Checks whether the item is "on" on the specified date/time. Item is considered "on" if it matches at least one "due" time and does not match any "omit" time. If it matches an omit time, then depending on the value of shift it may still be "on", or attempted to be rescheduled. Return values are: nil - item is not "on" / not "due" true - item is "on" (it is "due" and not on "omit" list) false - item is due, but that date is omitted, and no reschedule was requested or possible, so effectively it is not "on" Time::Span - span which is to be added to asked date to reach the earliest/closest time when item is "on"


[View source]
def shift : Nil | Bool | Time::Span #

Decision about an item to make if it falls on an omitted date/time.

Allowed values are:

  • nil: treat the item as non-applicable/not-scheduled on the specified date/time
  • false: treat the item as not due due to falling on an omitted date/time, after a reschedule was not attempted or was not able to find another spot
  • true: treat the item as due regardless of falling on an omitted date/time
  • Time::Span: shift the scheduled date/time by specified time span. Can be negative (for rescheduling before the original due) or positive (for rescheduling after the original due)).

If a time span is specified, shifting is performed incrementaly until a suitable date/time is found, or until max number of shift attempts is reached.


[View source]
def shift=(shift : Nil | Bool | Time::Span) #

Decision about an item to make if it falls on an omitted date/time.

Allowed values are:

  • nil: treat the item as non-applicable/not-scheduled on the specified date/time
  • false: treat the item as not due due to falling on an omitted date/time, after a reschedule was not attempted or was not able to find another spot
  • true: treat the item as due regardless of falling on an omitted date/time
  • Time::Span: shift the scheduled date/time by specified time span. Can be negative (for rescheduling before the original due) or positive (for rescheduling after the original due)).

If a time span is specified, shifting is performed incrementaly until a suitable date/time is found, or until max number of shift attempts is reached.


[View source]