Class: Cel::Timestamp

Inherits:
Literal
  • Object
show all
Defined in:
lib/cel/ast/elements.rb

Instance Attribute Summary

Attributes inherited from Literal

#type, #value

Instance Method Summary collapse

Methods inherited from Literal

#==, to_cel_type, #to_ruby_type

Constructor Details

#initialize(value) ⇒ Timestamp

Returns a new instance of Timestamp.



367
368
369
370
371
372
373
374
# File 'lib/cel/ast/elements.rb', line 367

def initialize(value)
  value = case value
          when ::String then Time.parse(value)
          when Numeric then Time.at(value)
          else value
  end
  super(:timestamp, value)
end

Instance Method Details

#+(other) ⇒ Object



376
377
378
# File 'lib/cel/ast/elements.rb', line 376

def +(other)
  Timestamp.new(@value + other.to_f)
end

#-(other) ⇒ Object



380
381
382
383
384
385
386
387
# File 'lib/cel/ast/elements.rb', line 380

def -(other)
  case other
  when Timestamp
    Duration.new(@value - other.value)
  when Duration
    Timestamp.new(@value - other.to_f)
  end
end

#getDate(tz = nil) ⇒ Object

Cel Functions



399
400
401
# File 'lib/cel/ast/elements.rb', line 399

def getDate(tz = nil)
  to_local_time(tz).day
end

#getDayOfMonth(tz = nil) ⇒ Object



403
404
405
# File 'lib/cel/ast/elements.rb', line 403

def getDayOfMonth(tz = nil)
  getDate(tz) - 1
end

#getDayOfWeek(tz = nil) ⇒ Object



407
408
409
# File 'lib/cel/ast/elements.rb', line 407

def getDayOfWeek(tz = nil)
  to_local_time(tz).wday
end

#getDayOfYear(tz = nil) ⇒ Object



411
412
413
# File 'lib/cel/ast/elements.rb', line 411

def getDayOfYear(tz = nil)
  to_local_time(tz).yday - 1
end

#getFullYear(tz = nil) ⇒ Object



419
420
421
# File 'lib/cel/ast/elements.rb', line 419

def getFullYear(tz = nil)
  to_local_time(tz).year
end

#getHours(tz = nil) ⇒ Object



423
424
425
# File 'lib/cel/ast/elements.rb', line 423

def getHours(tz = nil)
  to_local_time(tz).hour
end

#getMilliseconds(tz = nil) ⇒ Object



435
436
437
# File 'lib/cel/ast/elements.rb', line 435

def getMilliseconds(tz = nil)
  to_local_time(tz).nsec / 1_000_000
end

#getMinutes(tz = nil) ⇒ Object



427
428
429
# File 'lib/cel/ast/elements.rb', line 427

def getMinutes(tz = nil)
  to_local_time(tz).min
end

#getMonth(tz = nil) ⇒ Object



415
416
417
# File 'lib/cel/ast/elements.rb', line 415

def getMonth(tz = nil)
  to_local_time(tz).month - 1
end

#getSeconds(tz = nil) ⇒ Object



431
432
433
# File 'lib/cel/ast/elements.rb', line 431

def getSeconds(tz = nil)
  to_local_time(tz).sec
end