Project

General

Profile

Bug #7326 ยป time_patch0003.diff

bt (Bernd Homuth), 11/24/2012 07:38 PM

View differences:

time.c
2222 2222
 *
2223 2223
 *  Returns a Time object.
2224 2224
 *
2225
 *  It is initialized to the current system time if no argument.
2226
 *  <b>Note:</b> The object created will be created using the
2227
 *  resolution available on your system clock, and so may include
2228
 *  fractional seconds.
2225
 *  It is initialized to the current system time if no argument is given.
2226
 *
2227
 *  *Note:* The new object will use the resolution available on your
2228
 *  system clock, and may include fractional seconds.
2229 2229
 *
2230 2230
 *  If one or more arguments specified, the time is initialized
2231 2231
 *  to the specified time.
......
3118 3118
 *    Time.gm(year, month, day, hour, min, sec, usec_with_frac) -> time
3119 3119
 *    Time.gm(sec, min, hour, day, month, year, wday, yday, isdst, tz) -> time
3120 3120
 *
3121
 *  Creates a time based on given values, interpreted as UTC (GMT). The
3121
 *  Creates a Time object based on given values, interpreted as UTC (GMT). The
3122 3122
 *  year must be specified. Other values default to the minimum value
3123 3123
 *  for that field (and may be +nil+ or omitted). Months may
3124 3124
 *  be specified by numbers from 1 to 12, or by the three-letter English
......
3281 3281
 *
3282 3282
 *  The lowest digits of #to_f and #nsec are different because
3283 3283
 *  IEEE 754 double is not accurate enough to represent
3284
 *  nanoseconds from the Epoch.
3285
 *  The accurate value is returned by nsec.
3284
 *  the exact number of nanoseconds since the Epoch.
3285
 *
3286
 *  The more accurate value is returned by #nsec.
3286 3287
 */
3287 3288

  
3288 3289
static VALUE
......
3300 3301
 *
3301 3302
 *  Returns the fraction for _time_.
3302 3303
 *
3303
 *  The result is possibly rational.
3304
 *  The return value can be a rational number.
3304 3305
 *
3305 3306
 *     t = Time.now        #=> 2009-03-26 22:33:12 +0900
3306 3307
 *     "%10.9f" % t.to_f   #=> "1238074392.940563917"
......
3308 3309
 *
3309 3310
 *  The lowest digits of #to_f and #subsec are different because
3310 3311
 *  IEEE 754 double is not accurate enough to represent
3311
 *  the rational.
3312
 *  The accurate value is returned by subsec.
3312
 *  the rational number.
3313
 *
3314
 *  The more accurate value is returned by #subsec.
3313 3315
 */
3314 3316

  
3315 3317
static VALUE
......
3325 3327
 *  call-seq:
3326 3328
 *     time <=> other_time -> -1, 0, +1 or nil
3327 3329
 *
3328
 *  Comparison---Compares <i>time</i> with <i>other_time</i>.
3330
 *  Comparison---Compares _time_ with +other_time+.
3331
 *  The return value is ++1+ if _time_ is greater than
3332
 *  +other_time+, +0+ if _time_ is equal to +other_time+ and
3333
 *  +-1+ if _time_ is smaller than +other_time+.
3329 3334
 *
3330 3335
 *     t = Time.now       #=> 2007-11-19 08:12:12 -0600
3331 3336
 *     t2 = t + 2592000   #=> 2007-12-19 08:12:12 -0600
......
3678 3683
 *     time.inspect -> string
3679 3684
 *     time.to_s    -> string
3680 3685
 *
3681
 *  Returns a string representing <i>time</i>. Equivalent to calling
3682
 *  <code>Time#strftime</code> with a format string of
3683
 *  ``<code>%Y-%m-%d</code> <code>%H:%M:%S</code> <code>%z</code>''
3684
 *  for a local time and
3685
 *  ``<code>%Y-%m-%d</code> <code>%H:%M:%S</code> <code>UTC</code>''
3686
 *  for a UTC time.
3686
 *  Returns a string representing _time_. Equivalent to calling
3687
 *  #strftime with the appropriate format string.
3688
 *
3689
 *     t = Time.now
3690
 *     t.to_s                              => "2012-11-10 18:16:12 +0100"
3691
 *     t.strftime "%Y-%m-%d %H:%M:%S %z"   => "2012-11-10 18:16:12 +0100"
3687 3692
 *
3688
 *     Time.now.to_s       #=> "2007-10-05 16:09:51 +0900"
3689
 *     Time.now.utc.to_s   #=> "2007-10-05 07:09:51 UTC"
3693
 *     t.utc.to_s                          => "2012-11-10 17:16:12 UTC"
3694
 *     t.strftime "%Y-%m-%d %H:%M:%S UTC"  => "2012-11-10 17:16:12 UTC"
3690 3695
 */
3691 3696

  
3692 3697
static VALUE
......
3750 3755
 *     time - other_time -> float
3751 3756
 *     time - numeric    -> time
3752 3757
 *
3753
 *  Difference---Returns a new time that represents the difference
3754
 *  between two times, or subtracts the given number of seconds in
3755
 *  <i>numeric</i> from <i>time</i>.
3758
 *  Difference---Returns a new Time object that represents the difference
3759
 *  between _time_ and +other_time+, or subtracts the given number
3760
 *  of seconds in +numeric+ from _time_.
3756 3761
 *
3757 3762
 *     t = Time.now       #=> 2007-11-19 08:23:10 -0600
3758 3763
 *     t2 = t + 2592000   #=> 2007-12-19 08:23:10 -0600
......
3784 3789
 *
3785 3790
 *     t = Time.now       #=> 2007-11-19 08:23:57 -0600
3786 3791
 *     t.succ             #=> 2007-11-19 08:23:58 -0600
3792
 *
3793
 * Use instead <code>time + 1</code>
3794
 *
3795
 *     t + 1              #=> 2007-11-19 08:23:58 -0600
3787 3796
 */
3788 3797

  
3789 3798
VALUE
......
3882 3891
 *
3883 3892
 *  Returns the second of the minute (0..60) for _time_.
3884 3893
 *
3885
 *  <em>[Yes, seconds range from zero to 60.  This allows the system to inject
3886
 *  leap seconds.  See http://en.wikipedia.org/wiki/Leap_second for further
3887
 *  details.]</em>
3894
 *  *Note:* Seconds range from zero to 60 to allow the system to inject
3895
 *  leap seconds. See http://en.wikipedia.org/wiki/Leap_second for further
3896
 *  details.
3888 3897
 *
3889 3898
 *     t = Time.now   #=> 2007-11-19 08:25:02 -0600
3890 3899
 *     t.sec          #=> 2
......
4402 4411
 *    Date (Year, Month, Day):
4403 4412
 *      %Y - Year with century (can be negative, 4 digits at least)
4404 4413
 *              -0001, 0000, 1995, 2009, 14292, etc.
4405
 *      %C - year / 100 (round down.  20 in 2009)
4414
 *      %C - year / 100 (rounded down such as 20 in 2009)
4406 4415
 *      %y - year % 100 (00..99)
4407 4416
 *
4408 4417
 *      %m - Month of the year, zero-padded (01..12)
......
4491 4500
 *      %T - 24-hour time (%H:%M:%S)
4492 4501
 *
4493 4502
 *  This method is similar to strftime() function defined in ISO C and POSIX.
4494
 *  Several directives (%a, %A, %b, %B, %c, %p, %r, %x, %X, %E*, %O* and %Z)
4495
 *  are locale dependent in the function.
4496
 *  However this method is locale independent since Ruby 1.9.
4497
 *  (%Z is platform dependent, though.)
4498
 *  So, the result may differ even if a same format string is used in other
4503
 *
4504
 *  While all directives are locale independant since Ruby 1.9 %Z is platform
4505
 *  dependant.
4506
 *  So, the result may differ even if the same format string is used in other
4499 4507
 *  systems such as C.
4500
 *  It is good practice to avoid %x and %X because there are corresponding
4501
 *  locale independent representations, %D and %T.
4502 4508
 *
4503 4509
 *  %z is recommended over %Z.
4504 4510
 *  %Z doesn't identify the timezone.
4505 4511
 *  For example, "CST" is used at America/Chicago (-06:00),
4506 4512
 *  America/Havana (-05:00), Asia/Harbin (+08:00), Australia/Darwin (+09:30)
4507 4513
 *  and Australia/Adelaide (+10:30).
4508
 *  Also, %Z is highly dependent for OS.
4514
 *  Also, %Z is highly dependent on the operating system.
4509 4515
 *  For example, it may generate a non ASCII string on Japanese Windows.
4510 4516
 *  i.e. the result can be different to "JST".
4511 4517
 *  So the numeric time zone offset, %z, is recommended.
......
4863 4869
/*
4864 4870
 *  Time is an abstraction of dates and times. Time is stored internally as
4865 4871
 *  the number of seconds with fraction since the _Epoch_, January 1, 1970
4866
 *  00:00 UTC. Also see the library modules Date. The Time class treats GMT
4872
 *  00:00 UTC. Also see the library module Date. The Time class treats GMT
4867 4873
 *  (Greenwich Mean Time) and UTC (Coordinated Universal Time) as equivalent.
4868 4874
 *  GMT is the older way of referring to these baseline times but persists in
4869 4875
 *  the names of calls on POSIX systems.
......
4876 4882
 *  Bignum or Rational.
4877 4883
 *  The integer is a number of nanoseconds since the _Epoch_ which can
4878 4884
 *  represent 1823-11-12 to 2116-02-20.
4879
 *  When Bignum or Rational is used (before 1823, after 2116, under nanosecond),
4880
 *  Time works slower than the integer is used.
4885
 *  When Bignum or Rational is used (before 1823, after 2116, under
4886
 *  nanosecond), Time works slower as when integer is used.
4881 4887
 *
4882 4888
 *  = Examples
4883 4889
 *
......
4889 4895
 *  current system time. Time::now is an alias for this. You can also
4890 4896
 *  pass parts of the time to Time::new such as year, month, minute, etc. When
4891 4897
 *  you want to construct a time this way you must pass at least a year. If you
4892
 *  pass the year with nothing else time with default to January 1 of that year
4898
 *  pass the year with nothing else time will default to January 1 of that year
4893 4899
 *  at 00:00:00 with the current system timezone. Here are some examples:
4894 4900
 *
4895 4901
 *    Time.new(2002)         #=> 2002-01-01 00:00:00 -0500
......
4897 4903
 *    Time.new(2002, 10, 31) #=> 2002-10-31 00:00:00 -0500
4898 4904
 *    Time.new(2002, 10, 31, 2, 2, 2, "+02:00") #=> 2002-10-31 02:02:02 -0200
4899 4905
 *
4900
 *  You can also use #gm, #local and #utc to infer GMT, local and UTC
4901
 *  timezones instead of using the current system setting.
4906
 *  You can also use #gm, #local and
4907
 *  #utc to infer GMT, local and UTC timezones instead of using
4908
 *  the current system setting.
4902 4909
 *
4903 4910
 *  You can also create a new time using Time::at which takes the number of
4904 4911
 *  seconds (or fraction of seconds) since the {Unix
4905
-