Class: RubyJS.Time

Defined in: lib/corelib/time.coffee
Inherits: RubyJS.Object

Overview

new RubyJS.Time(new Date(), 3600)

JS Date objects have no support for timezones. R.Time emulates timezones using a second fake object that is offset by the user defined utc_offset.

Examples:

If local timezone is ICT (+07:00)


  t = R.Time.new(2012,12,24,12,0,0, "+01:00")
  t.__native__
  # => Mon Dec 24 2012 18:00:00 GMT+0700 (ICT)
  # t.__native__ has the correct timestamp for the local time.
  #              2012-12-24 12:00 (CET) - "+01:00 (CET)"
  #              2012-12-24 11:00 (UCT) + "+07:00 (ICT)"
  #              2012-12-24 18:00 (ICT)
  #
  t._tzdate
  # => Mon Dec 24 2012 12:00:00 GMT+0700 (ICT)
  #
  # t._tzdate holds the wrong timestamp but is useful to work with native JS
  # methods.
  #
  t.hour()      # => 12 (internally uses _tzdate.getHours())

Constant Summary

LOCALE =
{
  'DAYS': ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  'DAYS_SHORT': ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  'MONTHS': [null, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  'MONTHS_SHORT': [null, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  'AM': 'AM',
  'PM': 'PM',
  'AM_LOW': 'am',
  'PM_LOW': 'pm'
}
TIME_ZONES =
{
  'UTC': 0,
  'UT': 0,
  'GMT': 0,
  'EST': -5,
  'EDT': -4,
  'CST': -6,
  'CDT': -5,
  'MST': -7,
  'MDT': -6,
  'PST': -8,
  'PDT': -7
}

Class Method Summary

Instance Method Summary

Inherited Method Summary

Methods inherited from RubyJS.Object

.include, .__add_default_aliases__, #send, #respond_to, #to_enum, #tap

Class Method Details

+ (void) now()

+ (void) new(year, month, day, hour, min, sec, utc_offset)

new → time click to toggle source new(year, month=nil, day=nil, hour=nil, min=nil, sec=nil, utc_offset=nil) → time

+ (void) _local_to_offset(date, utc_offset)

+ (void) _offset_to_local(date, utc_offset)

+ (void) at(seconds, microseconds)

Creates a new time object with the value given by time, the given number of seconds_with_frac, or seconds and microseconds_with_frac from the Epoch. seconds_with_frac and microseconds_with_frac can be Integer, Float, Rational, or other Numeric. non-portable feature allows the offset to be negative on some systems.

Examples:

  R.Time.at(0)            #=> 1969-12-31 18:00:00 -0600
  R.Time.at(Time.at(0))   #=> 1969-12-31 18:00:00 -0600
  R.Time.at(946702800)    #=> 1999-12-31 23:00:00 -0600
  R.Time.at(-284061600)   #=> 1960-12-31 00:00:00 -0600
  R.Time.at(946684800.2).usec() #=> 200000
  R.Time.at(946684800, 123456.789).nsec() #=> 123456789

+ (void) local(year, month, day, hour, min, sec)

+ (void) utc(year, month, day, hour, min, sec)

TODO: unsupported c-style syntax R.Time.gm(1, 15, 20, 1, 1, 2000, 'ignored', 'ignored', 'ignored', 'ignored')

Creates a time based on given values, interpreted as UTC (GMT). The year must be specified. Other values default to the minimum value for that field (and may be nil or omitted). Months may be specified by numbers from 1 to 12, or by the three-letter English month names. Hours are specified on a 24-hour clock (0..23). Raises an ArgumentError if any values are out of range. Will also accept ten arguments in the order output by Time#to_a. sec_with_frac and usec_with_frac can have a fractional part.

@alias #gm

Examples:

  R.Time.utc(2000,"jan",1,20,15,1)  #=> 2000-01-01 20:15:01 UTC
  R.Time.gm(2000,"jan",1,20,15,1)   #=> 2000-01-01 20:15:01 UTC

+ (void) now()

Synonym for Time.new. Returns a Time object initialized to the current system time.

Constructor Details

- (void) constructor(__native__, utc_offset)

when passing utcoffset @_native has to be in that timezone as well. utc_offset is in seconds

e.g. to create a GMT date:

new R.Time(new Date(), 3600)

Instance Method Details

- (void) is_time()

'-instance'> - (void) '<=>'(other)

- (void) '=='(other)

- (void) '-'(other)

- (void) '+'(other)

- (void) asctime()

Returns a canonical string representation of time.

Time.now.asctime #=> "Wed Apr 9 08:56:03 2003"

@alias #ctime

- (void) dup()

- (void) year()

- (void) month()

@alias #mon

- (void) monday()

- (void) tuesday()

- (void) wednesday()

- (void) thursday()

- (void) friday()

- (void) saturday()

- (void) sunday()

- (void) day()

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

@alias #mday

Examples:

  t = Time.now()   #=> 2007-11-19 08:27:03 -0600
  t.day()          #=> 19
  t.mday()         #=> 19

- (void) getgm()

Returns a new new_time object representing time in UTC.

@alias #getutc

Examples:

  t = R.Time.local(2000,1,1,20,15,1)   #=> 2000-01-01 20:15:01 -0600
  t.gmt()                              #=> false
  y = t.getgm()                        #=> 2000-01-02 02:15:01 UTC
  y.gmt())                             #=> true
  t == y                               #=> true

- (void) gmt()

Returns true if time represents a time in UTC (GMT).

@alias #is_utc

Examples:


  t = Time.now()                      #=> 2007-11-19 08:15:23 -0600
  t.utc(                              #=> false
  t = Time.gm(2000,"jan",1,20,15,1)   #=> 2000-01-01 20:15:01 UTC
  t.utc()                             #=> true

  t = Time.now()                      #=> 2007-11-19 08:16:03 -0600
  t.gmt()                             #=> false
  t = Time.gm(2000,1,1,20,15,1)       #=> 2000-01-01 20:15:01 UTC
  t.gmt()                             #=> true

- (?) gmt_offset()

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

@offset t = R.Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC t.gmt_offset() #=> 0 l = t.getlocal() #=> 2000-01-01 14:15:01 -0600 l.gmt_offset() #=> -21600

@alias #gmtoff, #utc_offset

Returns:

  • (?) — R.Fixnum offset in seconds

- (void) gmtime()

Converts time to UTC (GMT), modifying the receiver.

t = Time.now #=> 2007-11-19 08:18:31 -0600 t.gmt? #=> false t.gmtime #=> 2007-11-19 14:18:31 UTC t.gmt? #=> true

- (void) hour()

- (void) hour12()

- (void) inspect()

- (void) min()

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

Examples:


  t = R.Time.now()   #=> 2007-11-19 08:25:51 -0600
  t.min()            #=> 25

- (void) sec()

Returns the second of the minute (0..60)[Yes, seconds really can range from zero to 60. This allows the system to inject leap seconds every now and then to correct for the fact that years are not really a convenient number of hours long.] for time.

Examples:


  t = R.Time.now()   #=> 2007-11-19 08:25:02 -0600
  t.sec()            #=> 2

- (void) strftime(format)

@todo: implement %N

- (void) succ()

- (void) to_i()

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

Examples:

  t = R.Time.now()
  "%10.5f" % t.to_f   #=> "1270968656.89607"
  t.to_i              #=> 1270968656

- (void) to_f()

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

t = R.Time.now() "%10.5f" % t.to_f #=> "1270968744.77658" t.to_i #=> 1270968744 Note that IEEE 754 double is not accurate enough to represent number of nanoseconds from the Epoch.

- (void) __tz_delta__()

- (void) __utc_delta__()

Return 0 if local timezone matches gmt_offset. otherwise the difference to UTC

- (void) tv_usec()

TODO: implement

Returns just the number of microseconds for time.

@alias #usec

Examples:

  t = Time.now        #=> 2007-11-19 08:03:26 -0600
  "%10.6f" % t.to_f   #=> "1195481006.775195"
  t.usec              #=> 775195

- (void) wday()

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

Examples:

  t = Time.now()   #=> 2007-11-20 02:35:35 -0600
  t.wday()         #=> 2
  t.sunday()      #=> false
  t.monday()      #=> false
  t.tuesday()     #=> true
  t.wednesday()   #=> false
  t.thursday()    #=> false
  t.friday()      #=> false
  t.saturday()    #=> false

- (void) yday()

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

Examples:

  t = Time.now()   #=> 2007-11-19 08:32:31 -0600
  t.yday()         #=> 323

- (void) valueOf()

- (void) zone()

TODO: implement

Returns the name of the time zone used for time. As of Ruby 1.8, returns “UTC” rather than “GMT” for UTC times.

zone: -> t = Math.floor(@gmt_offset() / 60 * 60) for own zone, i in R.Time.TIME_ZONES return R(zone) if t == i null

Examples:

  t = R.Time.gm(2000, "jan", 1, 20, 15, 1)
  t.zone()   #=> "UTC"
  t = Time.local(2000, "jan", 1, 20, 15, 1)
  t.zone()   #=> "CST"

- (void) _rjust(fixnum, str = '0')

- (void) _offset_str()