View Source Trifle.Stats.Nocturnal (Trifle.Stats v2.5.0)

Summary

Functions

Add time offset to the current time based on unit. Supports both positive (forward) and negative (backward) offsets.

Floor time to the segment boundary based on offset and unit. Handles edge cases like 33-minute segments that create uneven boundaries.

Create a new Nocturnal instance with time and config.

Create timeline using string-based granularity.

Functions

Link to this function

add(nocturnal, offset, unit)

View Source

Add time offset to the current time based on unit. Supports both positive (forward) and negative (backward) offsets.

Examples

nocturnal = Trifle.Stats.Nocturnal.new(~U[2025-08-17 10:30:00Z], config)
new_time = Trifle.Stats.Nocturnal.add(nocturnal, 15, :minute)
# Returns time 15 minutes later

past_time = Trifle.Stats.Nocturnal.add(nocturnal, -24, :hour)
# Returns time 24 hours earlier
Link to this function

floor(nocturnal, offset, unit)

View Source

Floor time to the segment boundary based on offset and unit. Handles edge cases like 33-minute segments that create uneven boundaries.

Examples

nocturnal = Trifle.Stats.Nocturnal.new(~U[2025-08-17 10:37:45Z], config)
floored = nocturnal.floor(15, :minute)
# Returns ~U[2025-08-17 10:30:00Z] (start of 15-minute segment)

# Edge case with 33-minute segments
floored = nocturnal.floor(33, :minute)
# For 10:37:45, returns ~U[2025-08-17 10:33:00Z] (33-59 segment)

Create a new Nocturnal instance with time and config.

Examples

nocturnal = Trifle.Stats.Nocturnal.new(~U[2025-08-17 10:30:00Z], config)
@spec timeline([
  {:config, any()}
  | {:from, any()}
  | {:offset, pos_integer()}
  | {:to, any()}
  | {:unit,
     :day | :hour | :minute | :month | :quarter | :second | :week | :year},
  ...
]) :: list()

Create timeline using string-based granularity.

Examples

config = Trifle.Stats.Configuration.configure(nil)
timeline = Trifle.Stats.Nocturnal.timeline(
  from: ~U[2025-08-17 10:00:00Z],
  to: ~U[2025-08-17 12:00:00Z],
  offset: 15,
  unit: :minute,
  config: config
)