Module: Gemvault::Timestamp

Defined in:
lib/gemvault/timestamp.rb

Overview

The notation a vault records times in.

A manifest is a table of whitespace-separated fields (see Gemvault::ManifestText), so a stored time may not contain a space. ISO 8601 in UTC satisfies that, sorts lexically, and is what a reader expects.

Legacy SQLite vaults stored "2000-01-01 00:00:00", and gemvault upgrade carries those values straight into the new vault, so the two known notations are accepted and everything else is refused rather than written into a manifest it would corrupt.

Defined Under Namespace

Classes: Error

Constant Summary collapse

FORMAT =
"%Y-%m-%dT%H:%M:%SZ".freeze
CANONICAL =

What FORMAT produces: 2026-08-12T16:05:55Z.

/\A\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ\z/
LEGACY =

What Dbvault wrote: the same instant with a space for the T and no zone.

/\A(\d{4}-\d\d-\d\d) (\d\d:\d\d:\d\d)\z/

Class Method Summary collapse

Class Method Details

.canonical(value) ⇒ Object

:call-seq:

canonical(value) -> String

value in the vault's notation, converting a legacy vault's notation on the way. Raises Error for anything else.

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/gemvault/timestamp.rb', line 35

def canonical(value)
  text = value.to_s
  return text if CANONICAL.match?(text)

  legacy = LEGACY.match(text)
  raise Error, "Not a time a vault can store: #{text.inspect}" unless legacy

  "#{legacy[1]}T#{legacy[2]}Z"
end

.nowObject

This instant, in the vault's notation.



28
# File 'lib/gemvault/timestamp.rb', line 28

def now = Time.now.utc.strftime(FORMAT)