Class: Time
Overview
Time
Class Method Summary collapse
-
.at(seconds, milliseconds) ⇒ Object
call-seq: Time.at(a_time) -> time Time.at(seconds [, microseconds]) -> time.
-
.now ⇒ Object
call-seq: Time.new -> time Time.now -> time.
Instance Method Summary collapse
-
#+(numeric) ⇒ Object
call-seq: time + numeric -> time.
-
#-(time) ⇒ Object
call-seq: time - other -> float time - numeric -> time.
-
#<=>(time) ⇒ Object
call-seq: time <=> other -> -1, 0, 1 time <=> numeric -> -1, 0, 1.
-
#day ⇒ Object
call-seq: time.day -> integer time.mday -> integer.
-
#dst? ⇒ Boolean
FIX: Incomplete.
-
#eql?(time) ⇒ Boolean
call-seq: time.eql?(other) -> true or false.
-
#getgm ⇒ Object
FIX: Incomplete.
-
#getlocal ⇒ Object
FIX: Incomplete.
-
#getutc ⇒ Object
FIX: Incomplete.
-
#gmt? ⇒ Boolean
FIX: Incomplete.
-
#gmt_offset ⇒ Object
call-seq: time.gmt_offset -> integer time.gmtoff -> integer time.utc_offset -> integer.
-
#gmtime ⇒ Object
FIX: Incomplete.
-
#gmtoff ⇒ Object
call-seq: time.gmt_offset -> integer time.gmtoff -> integer time.utc_offset -> integer.
-
#hash ⇒ Object
:nodoc:.
-
#hour ⇒ Object
call-seq: time.hour -> integer.
-
#initialize ⇒ Time
constructor
call-seq: Time.new -> time Time.now -> time.
-
#inspect ⇒ Object
call-seq: time.inspect -> string time.to_s -> string.
-
#isdst ⇒ Object
FIX: Incomplete.
-
#localtime ⇒ Object
FIX: Incomplete.
-
#mday ⇒ Object
call-seq: time.day -> integer time.mday -> integer.
-
#min ⇒ Object
call-seq: time.min -> integer.
-
#mon ⇒ Object
call-seq: time.mon -> integer time.month -> integer.
-
#month ⇒ Object
call-seq: time.mon -> integer time.month -> integer.
-
#sec ⇒ Object
call-seq: time.sec -> integer.
-
#strftime ⇒ Object
FIX: Incomplete.
-
#succ ⇒ Object
call-seq: time.succ -> new_time.
-
#to_a ⇒ Object
call-seq: time.to_a -> array.
-
#to_f ⇒ Object
call-seq: time.to_f -> numeric.
-
#to_i ⇒ Object
call-seq: time.to_i -> integer.
-
#to_s ⇒ Object
call-seq: time.inspect -> string time.to_s -> string.
-
#tv_sec ⇒ Object
call-seq: time.to_i -> integer.
-
#tv_usec ⇒ Object
call-seq: time.tv_usec -> integer time.usec -> integer.
-
#usec ⇒ Object
call-seq: time.tv_usec -> integer time.usec -> integer.
-
#utc ⇒ Object
FIX: Incomplete.
-
#utc? ⇒ Boolean
FIX: Incomplete.
-
#utc_offset ⇒ Object
call-seq: time.gmt_offset -> integer time.gmtoff -> integer time.utc_offset -> integer.
-
#wday ⇒ Object
call-seq: time.wday -> integer.
-
#yday ⇒ Object
call-seq: time.yday -> integer.
-
#year ⇒ Object
call-seq: time.year -> integer.
-
#zone ⇒ Object
FIX: Incomplete.
Constructor Details
#initialize ⇒ Time
call-seq:
Time.new -> time
Time.now -> time
Returns a Time object initialized to the current system time. The object created will include fractional seconds to the thousandths place.
t1 = Time.new #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t2 = Time.new #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t1 == t2 #=> false
t1.to_f #=> 1222222222.989
t2.to_f #=> 1222222222.991
6303 6304 6305 |
# File 'lib/source/ruby.rb', line 6303 def initialize `this._value=new(Date)` end |
Class Method Details
.at(seconds, milliseconds) ⇒ Object
call-seq:
Time.at(a_time) -> time
Time.at(seconds [, microseconds]) -> time
Creates a new time object with the value given by a_time, or the given number of seconds (and optional milliseconds) from epoch. A non-portable feature allows the offset to be negative on some systems.
Time.at(0) #=> Wed Dec 31 1969 19:00:00 GMT-0500 (EST)
Time.at(946702800) #=> Sat Jan 01 2000 00:00:00 GMT-0500 (EST)
Time.at(-284061600) #=> Sat Dec 31 1960 01:00:00 GMT-0500 (EST)
6267 6268 6269 6270 6271 |
# File 'lib/source/ruby.rb', line 6267 def self.at(seconds,milliseconds) `var t=c$Time.m$new()` `t._value=typeof(seconds)=='number'?new(Date)(seconds*1000+(milliseconds||0)):seconds._value` return `t` end |
.now ⇒ Object
call-seq:
Time.new -> time
Time.now -> time
Returns a Time object initialized to the current system time. The object created will include fractional seconds to the thousandths place.
t1 = Time.now #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t2 = Time.now #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t1 == t2 #=> false
t1.to_f #=> 1222222222.989
t2.to_f #=> 1222222222.991
6286 6287 6288 |
# File 'lib/source/ruby.rb', line 6286 def self.now Time.new end |
Instance Method Details
#+(numeric) ⇒ Object
6316 6317 6318 6319 6320 |
# File 'lib/source/ruby.rb', line 6316 def +(numeric) `var t=c$Time.m$new()` `t._value=new(Date)(numeric*1000+this._value.valueOf())` return `t` end |
#-(time) ⇒ Object
call-seq:
time - other -> float
time - numeric -> time
Difference – returns a new time that represents the difference between two times, or subtracts the given number of seconds in numeric from time.
t = Time.now #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t2 = t + 2592000 #=> Thu Oct 23 2008 22:10:22 GMT-0400 (EDT)
t2 - t #=> 2592000.0
t2 - 2592000 #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
6335 6336 6337 |
# File 'lib/source/ruby.rb', line 6335 def -(time) `typeof(time)=='number'?new(Date)(this._value.valueOf()-(time*1000)):(this._value.valueOf()-time._value.valueOf())/1000` end |
#<=>(time) ⇒ Object
call-seq:
time <=> other -> -1, 0, 1
time <=> numeric -> -1, 0, 1
Comparison – compares time with other or with numeric, which is the number of seconds (possibly fractional) since epoch.
t1 = Time.now #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t2 = t1 + 2592000 #=> Thu Oct 23 2008 22:10:22 GMT-0400 (EDT)
t1 <=> t2 #=> -1
t2 <=> t1 #=> 1
t1 <=> t1 #=> 0
6352 6353 6354 6355 6356 6357 6358 |
# File 'lib/source/ruby.rb', line 6352 def <=>(time) `var v=this._value.valueOf(),ms=typeof(time)=='number'?time*1000:time._value.valueOf()` `if(v<ms){return -1;}` `if(v==ms){return 0;}` `if(v>ms){return 1;}` return nil end |
#day ⇒ Object
6369 6370 6371 |
# File 'lib/source/ruby.rb', line 6369 def day `this._value.getDate()` end |
#dst? ⇒ Boolean
FIX: Incomplete
6374 6375 |
# File 'lib/source/ruby.rb', line 6374 def dst? end |
#eql?(time) ⇒ Boolean
call-seq:
time.eql?(other) -> true or false
Return true if time and other are both Time objects with the same seconds and fractional seconds.
6383 6384 6385 6386 |
# File 'lib/source/ruby.rb', line 6383 def eql?(time) `if(time.constructor!=c$Time){return false;}` `this._value.valueOf()==time._value.valueOf()` end |
#getlocal ⇒ Object
FIX: Incomplete
6393 6394 |
# File 'lib/source/ruby.rb', line 6393 def getlocal end |
#gmt? ⇒ Boolean
FIX: Incomplete
6401 6402 |
# File 'lib/source/ruby.rb', line 6401 def gmt? end |
#gmt_offset ⇒ Object
6414 6415 6416 |
# File 'lib/source/ruby.rb', line 6414 def gmt_offset `this._value.getTimezoneOffset() * -60` end |
#gmtoff ⇒ Object
6432 6433 6434 |
# File 'lib/source/ruby.rb', line 6432 def gmtoff `this._value.getTimezoneOffset() * -60` end |
#hash ⇒ Object
:nodoc:
6436 6437 6438 |
# File 'lib/source/ruby.rb', line 6436 def hash # :nodoc: `'t_'+this._value.valueOf()/1000` end |
#hour ⇒ Object
6448 6449 6450 |
# File 'lib/source/ruby.rb', line 6448 def hour `this._value.getHours()` end |
#inspect ⇒ Object
6460 6461 6462 |
# File 'lib/source/ruby.rb', line 6460 def inspect `$q(''+this)` end |
#localtime ⇒ Object
FIX: Incomplete
6469 6470 |
# File 'lib/source/ruby.rb', line 6469 def localtime end |
#mday ⇒ Object
6481 6482 6483 |
# File 'lib/source/ruby.rb', line 6481 def mday `this._value.getDate()` end |
#min ⇒ Object
6493 6494 6495 |
# File 'lib/source/ruby.rb', line 6493 def min `this._value.getMinutes()` end |
#mon ⇒ Object
6506 6507 6508 |
# File 'lib/source/ruby.rb', line 6506 def mon `this._value.getMonth()` end |
#month ⇒ Object
6519 6520 6521 |
# File 'lib/source/ruby.rb', line 6519 def month `this._value.getMonth()` end |
#sec ⇒ Object
6531 6532 6533 |
# File 'lib/source/ruby.rb', line 6531 def sec `this._value.getSeconds()` end |
#strftime ⇒ Object
FIX: Incomplete
6536 6537 |
# File 'lib/source/ruby.rb', line 6536 def strftime end |
#succ ⇒ Object
call-seq:
time.succ -> new_time
Returns a new time object, one second later than time.
6544 6545 6546 6547 6548 |
# File 'lib/source/ruby.rb', line 6544 def succ `var t=c$Time.m$new()` `t._value=new(Date)(1000+this._value.valueOf())` return `t` end |
#to_a ⇒ Object
call-seq:
time.to_a -> array
Returns a ten-element array of values for time: [ sec, min, hour, day, month, year, wday, yday, isdst, zone ]<tt/>. The ten elements can be passed directly to <tt>Time::utc or Time::local to create a new Time.
t = Time.now #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.to_a #=> [22, 10, 22, 23, 9, 2008, 2, 267, true, "EDT"]
FIX: Incomplete
6562 6563 6564 |
# File 'lib/source/ruby.rb', line 6562 def to_a [] end |
#to_f ⇒ Object
6575 6576 6577 |
# File 'lib/source/ruby.rb', line 6575 def to_f `this._value.valueOf()/1000` end |
#to_i ⇒ Object
6587 6588 6589 |
# File 'lib/source/ruby.rb', line 6587 def to_i `parseInt(this._value.valueOf()/1000)` end |
#to_s ⇒ Object
6599 6600 6601 |
# File 'lib/source/ruby.rb', line 6599 def to_s `$q(''+this._value)` end |
#tv_sec ⇒ Object
6611 6612 6613 |
# File 'lib/source/ruby.rb', line 6611 def tv_sec `parseInt(this._value.valueOf()/1000)` end |
#tv_usec ⇒ Object
6625 6626 6627 |
# File 'lib/source/ruby.rb', line 6625 def tv_usec `parseInt(this._value.valueOf()/1000)` end |
#usec ⇒ Object
6639 6640 6641 6642 |
# File 'lib/source/ruby.rb', line 6639 def usec `var v = this._value.valueOf()` `(v*1000)-parseInt(v/1000)*1000000` end |
#utc? ⇒ Boolean
FIX: Incomplete
6649 6650 |
# File 'lib/source/ruby.rb', line 6649 def utc? end |
#utc_offset ⇒ Object
6662 6663 6664 |
# File 'lib/source/ruby.rb', line 6662 def utc_offset `this._value.getTimezoneOffset() * -60` end |
#wday ⇒ Object
6674 6675 6676 |
# File 'lib/source/ruby.rb', line 6674 def wday `this._value.getDay()` end |
#yday ⇒ Object
6686 6687 6688 6689 |
# File 'lib/source/ruby.rb', line 6686 def yday `var d2=new Date(),d1=new Date(new Date(new Date().setFullYear(d2.getFullYear(),0,0)).setHours(0,0,0,0))` `parseInt((d2-d1)/1000/60/60/24)` end |
#year ⇒ Object
6699 6700 6701 |
# File 'lib/source/ruby.rb', line 6699 def year `this._value.getFullYear()` end |