Class: Time

Inherits:
Object show all
Defined in:
lib/source/ruby.rb

Overview

Time

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTime

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


6313
6314
6315
# File 'lib/source/ruby.rb', line 6313

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)


6277
6278
6279
6280
6281
# File 'lib/source/ruby.rb', line 6277

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

.nowObject

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


6296
6297
6298
# File 'lib/source/ruby.rb', line 6296

def self.now
  Time.new
end

Instance Method Details

#+(numeric) ⇒ Object

call-seq:

time + numeric -> time

Addition – adds some number of seconds (possibly fractional) to time and returns that value as a new time.

t = Time.now         #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t + (60 * 60 * 24)   #=> Wed Sep 24 2008 22:10:22 GMT-0400 (EDT)


6326
6327
6328
6329
6330
# File 'lib/source/ruby.rb', line 6326

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)


6345
6346
6347
# File 'lib/source/ruby.rb', line 6345

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


6362
6363
6364
6365
6366
6367
6368
# File 'lib/source/ruby.rb', line 6362

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

#dayObject

call-seq:

time.day  -> integer
time.mday -> integer

Returns the day of the month (1..n) for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.day           #=> 23


6379
6380
6381
# File 'lib/source/ruby.rb', line 6379

def day
  `this._value.getDate()`
end

#dst?Boolean

FIX: Incomplete

Returns:

  • (Boolean)


6384
6385
# File 'lib/source/ruby.rb', line 6384

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.

Returns:

  • (Boolean)


6393
6394
6395
6396
# File 'lib/source/ruby.rb', line 6393

def eql?(time)
  `if(time.constructor!=c$Time){return false;}`
  `this._value.valueOf()==time._value.valueOf()`
end

#getgmObject

FIX: Incomplete



6399
6400
# File 'lib/source/ruby.rb', line 6399

def getgm
end

#getlocalObject

FIX: Incomplete



6403
6404
# File 'lib/source/ruby.rb', line 6403

def getlocal
end

#getutcObject

FIX: Incomplete



6407
6408
# File 'lib/source/ruby.rb', line 6407

def getutc
end

#gmt?Boolean

FIX: Incomplete

Returns:

  • (Boolean)


6411
6412
# File 'lib/source/ruby.rb', line 6411

def gmt?
end

#gmt_offsetObject

call-seq:

time.gmt_offset -> integer
time.gmtoff     -> integer
time.utc_offset -> integer

Returns the offset in seconds between the timezone of time and UTC.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.gmt_offset    #=> -14400


6424
6425
6426
# File 'lib/source/ruby.rb', line 6424

def gmt_offset
  `this._value.getTimezoneOffset() * -60`
end

#gmtimeObject

FIX: Incomplete



6429
6430
# File 'lib/source/ruby.rb', line 6429

def gmtime
end

#gmtoffObject

call-seq:

time.gmt_offset -> integer
time.gmtoff     -> integer
time.utc_offset -> integer

Returns the offset in seconds between the timezone of time and UTC.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.gmtoff        #=> -14400


6442
6443
6444
# File 'lib/source/ruby.rb', line 6442

def gmtoff
  `this._value.getTimezoneOffset() * -60`
end

#hashObject

:nodoc:



6446
6447
6448
# File 'lib/source/ruby.rb', line 6446

def hash # :nodoc:
  `'t_'+this._value.valueOf()/1000`
end

#hourObject

call-seq:

time.hour -> integer

Returns the hour of the day (0..23) for time.

t = Time.now   #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.hour         #=> 22


6458
6459
6460
# File 'lib/source/ruby.rb', line 6458

def hour
  `this._value.getHours()`
end

#inspectObject

call-seq:

time.inspect -> string
time.to_s    -> string

Returns a string representing time.

Time.now.inspect    #=> "Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)"


6470
6471
6472
# File 'lib/source/ruby.rb', line 6470

def inspect
  `$q(''+this)`
end

#isdstObject

FIX: Incomplete



6475
6476
# File 'lib/source/ruby.rb', line 6475

def isdst
end

#localtimeObject

FIX: Incomplete



6479
6480
# File 'lib/source/ruby.rb', line 6479

def localtime
end

#mdayObject

call-seq:

time.day  -> integer
time.mday -> integer

Returns the day of the month (1..n) for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.mday          #=> 23


6491
6492
6493
# File 'lib/source/ruby.rb', line 6491

def mday
  `this._value.getDate()`
end

#minObject

call-seq:

time.min -> integer

Returns the minute of the hour (0..59) for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.min           #=> 10


6503
6504
6505
# File 'lib/source/ruby.rb', line 6503

def min
  `this._value.getMinutes()`
end

#monObject

call-seq:

time.mon   -> integer
time.month -> integer

Returns the month of the year (1..12) for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.mon           #=> 9


6516
6517
6518
# File 'lib/source/ruby.rb', line 6516

def mon
  `this._value.getMonth()`
end

#monthObject

call-seq:

time.mon   -> integer
time.month -> integer

Returns the month of the year (1..12) for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.month         #=> 9


6529
6530
6531
# File 'lib/source/ruby.rb', line 6529

def month
  `this._value.getMonth()`
end

#secObject

call-seq:

time.sec -> integer

Returns the second of the minute (0..59) for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.sec           #=> 22


6541
6542
6543
# File 'lib/source/ruby.rb', line 6541

def sec
  `this._value.getSeconds()`
end

#strftimeObject

FIX: Incomplete



6546
6547
# File 'lib/source/ruby.rb', line 6546

def strftime
end

#succObject

call-seq:

time.succ -> new_time

Returns a new time object, one second later than time.



6554
6555
6556
6557
6558
# File 'lib/source/ruby.rb', line 6554

def succ
  `var t=c$Time.m$new()`
  `t._value=new(Date)(1000+this._value.valueOf())`
  return `t`
end

#to_aObject

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



6572
6573
6574
# File 'lib/source/ruby.rb', line 6572

def to_a
  []
end

#to_fObject

call-seq:

time.to_f -> numeric

Returns the value of time as a floating point number of seconds since epoch.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.to_f          #=> 1222222222.989


6585
6586
6587
# File 'lib/source/ruby.rb', line 6585

def to_f
  `this._value.valueOf()/1000`
end

#to_iObject

call-seq:

time.to_i -> integer

Returns the value of time as an integer number of seconds since epoch.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.to_i          #=> 1222222222


6597
6598
6599
# File 'lib/source/ruby.rb', line 6597

def to_i
  `parseInt(this._value.valueOf()/1000)`
end

#to_sObject

call-seq:

time.inspect -> string
time.to_s    -> string

Returns a string representing time.

Time.now.to_s   #=> "Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)"


6609
6610
6611
# File 'lib/source/ruby.rb', line 6609

def to_s
  `$q(''+this._value)`
end

#tv_secObject

call-seq:

time.to_i -> integer

Returns the value of time as an integer number of seconds since epoch.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.tv_sec        #=> 1222222222


6621
6622
6623
# File 'lib/source/ruby.rb', line 6621

def tv_sec
  `parseInt(this._value.valueOf()/1000)`
end

#tv_usecObject

call-seq:

time.tv_usec -> integer
time.usec    -> integer

Returns just the number of microseconds for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.to_f          #=> 1222222222.989
t.tv_usec       #=> 989000


6635
6636
6637
# File 'lib/source/ruby.rb', line 6635

def tv_usec
  `parseInt(this._value.valueOf()/1000)`
end

#usecObject

call-seq:

time.tv_usec -> integer
time.usec    -> integer

Returns just the number of microseconds for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.to_f          #=> 1222222222.989
t.usec          #=> 989000


6649
6650
6651
6652
# File 'lib/source/ruby.rb', line 6649

def usec
  `var v = this._value.valueOf()`
  `(v*1000)-parseInt(v/1000)*1000000`
end

#utcObject

FIX: Incomplete



6655
6656
# File 'lib/source/ruby.rb', line 6655

def utc
end

#utc?Boolean

FIX: Incomplete

Returns:

  • (Boolean)


6659
6660
# File 'lib/source/ruby.rb', line 6659

def utc?
end

#utc_offsetObject

call-seq:

time.gmt_offset -> integer
time.gmtoff     -> integer
time.utc_offset -> integer

Returns the offset in seconds between the timezone of time and UTC.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.utc_offset    #=> -14400


6672
6673
6674
# File 'lib/source/ruby.rb', line 6672

def utc_offset
  `this._value.getTimezoneOffset() * -60`
end

#wdayObject

call-seq:

time.wday -> integer

Returns an integer representing the day of the week, 0..6, with Sunday == 0.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.wday          #=> 2


6684
6685
6686
# File 'lib/source/ruby.rb', line 6684

def wday
  `this._value.getDay()`
end

#ydayObject

call-seq:

time.yday -> integer

Returns an integer representing the day of the year, 1..366.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.yday          #=> 267


6696
6697
6698
6699
# File 'lib/source/ruby.rb', line 6696

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

#yearObject

call-seq:

time.year -> integer

Returns the four-digit year for time.

t = Time.now    #=> Tue Sep 23 2008 22:10:22 GMT-0400 (EDT)
t.year          #=> 2008


6709
6710
6711
# File 'lib/source/ruby.rb', line 6709

def year
  `this._value.getFullYear()`
end

#zoneObject

FIX: Incomplete



6714
6715
# File 'lib/source/ruby.rb', line 6714

def zone
end