Module: Timet::ItemDataHelper

Defined in:
lib/timet/item_data_helper.rb

Overview

Helper methods for fetching item data.

Class Method Summary collapse

Class Method Details

.fetch_item_after_start(db, id) ⇒ Integer

Fetches the start time of the tracking item after the current one.

Examples:

Fetch the start time of the next tracking item

fetch_item_after_start(db, id)

Parameters:

  • db (Timet::Database)

    The database instance.

  • id (Integer)

    The ID of the current tracking item.

Returns:

  • (Integer)

    The start time of the next tracking item in epoch format.



55
56
57
# File 'lib/timet/item_data_helper.rb', line 55

def fetch_item_after_start(db, id)
  db.find_item(id + 1)&.dig(Timet::Application::FIELD_INDEX['start']) || TimeHelper.current_timestamp
end

.fetch_item_before_end(db, id, item_start) ⇒ Integer

Fetches the end time of the tracking item before the current one.

Examples:

Fetch the end time of the previous tracking item

fetch_item_before_end(db, 1, 1633072800)

Parameters:

  • db (Timet::Database)

    The database instance.

  • id (Integer)

    The ID of the current tracking item.

  • item_start (Integer)

    The start time of the current tracking item.

Returns:

  • (Integer)

    The end time of the previous tracking item in epoch format.



42
43
44
# File 'lib/timet/item_data_helper.rb', line 42

def fetch_item_before_end(db, id, item_start)
  db.find_item(id - 1)&.dig(Timet::Application::FIELD_INDEX['end']) || item_start
end

.fetch_item_end(item) ⇒ Integer

Fetches the end time of a tracking item.

Examples:

Fetch the end time of a tracking item

fetch_item_end(item)

Parameters:

  • item (Array)

    The tracking item.

Returns:

  • (Integer)

    The end time in epoch format.



28
29
30
# File 'lib/timet/item_data_helper.rb', line 28

def fetch_item_end(item)
  item[Timet::Application::FIELD_INDEX['end']] || TimeHelper.current_timestamp
end

.fetch_item_start(item) ⇒ Integer

Fetches the start time of a tracking item.

Examples:

Fetch the start time of a tracking item

fetch_item_start(item)

Parameters:

  • item (Array)

    The tracking item.

Returns:

  • (Integer)

    The start time in epoch format.



16
17
18
# File 'lib/timet/item_data_helper.rb', line 16

def fetch_item_start(item)
  item[Timet::Application::FIELD_INDEX['start']]
end