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

Constructor Details

#initialize(value) ⇒ Timestamp

Returns a new instance of Timestamp.



347
348
349
350
351
352
353
354
# File 'lib/cel/ast/elements.rb', line 347

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



356
357
358
# File 'lib/cel/ast/elements.rb', line 356

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

#-(other) ⇒ Object



360
361
362
363
364
365
366
367
# File 'lib/cel/ast/elements.rb', line 360

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



379
380
381
# File 'lib/cel/ast/elements.rb', line 379

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

#getDayOfMonth(tz = nil) ⇒ Object



383
384
385
# File 'lib/cel/ast/elements.rb', line 383

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

#getDayOfWeek(tz = nil) ⇒ Object



387
388
389
# File 'lib/cel/ast/elements.rb', line 387

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

#getDayOfYear(tz = nil) ⇒ Object



391
392
393
# File 'lib/cel/ast/elements.rb', line 391

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

#getFullYear(tz = nil) ⇒ Object



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

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

#getHours(tz = nil) ⇒ Object



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

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

#getMilliseconds(tz = nil) ⇒ Object



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

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

#getMinutes(tz = nil) ⇒ Object



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

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

#getMonth(tz = nil) ⇒ Object



395
396
397
# File 'lib/cel/ast/elements.rb', line 395

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

#getSeconds(tz = nil) ⇒ Object



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

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