~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to time.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-05-16 12:37:06 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080516123706-r4llcdfd35aobrjv
Tags: 1.9.0.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.
* debian/control:
  - ruby1.9 pkg: moved rdoc1.9 suggestion to depends. (LP: #228345)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
  time.c -
4
4
 
5
 
  $Author: nahi $
6
 
  $Date: 2007-12-15 10:14:25 +0900 (Sat, 15 Dec 2007) $
 
5
  $Author: matz $
7
6
  created at: Tue Dec 28 14:31:59 JST 1993
8
7
 
9
8
  Copyright (C) 1993-2007 Yukihiro Matsumoto
13
12
#include "ruby/ruby.h"
14
13
#include <sys/types.h>
15
14
#include <time.h>
 
15
#include "ruby/encoding.h"
16
16
 
17
17
#ifdef HAVE_UNISTD_H
18
18
#include <unistd.h>
419
419
            tm->tm_mon = -1;
420
420
            for (i=0; i<12; i++) {
421
421
                if (RSTRING_LEN(s) == 3 &&
422
 
                    strcasecmp(months[i], RSTRING_PTR(v[1])) == 0) {
 
422
                    STRCASECMP(months[i], RSTRING_PTR(s)) == 0) {
423
423
                    tm->tm_mon = i;
424
424
                    break;
425
425
                }
1040
1040
/*
1041
1041
 *  call-seq:
1042
1042
 *     time <=> other_time => -1, 0, +1 
1043
 
 *     time <=> numeric    => -1, 0, +1
1044
1043
 *  
1045
 
 *  Comparison---Compares <i>time</i> with <i>other_time</i> or with
1046
 
 *  <i>numeric</i>, which is the number of seconds (possibly
1047
 
 *  fractional) since the Epoch.
 
1044
 *  Comparison---Compares <i>time</i> with <i>other_time</i>.
1048
1045
 *     
1049
1046
 *     t = Time.now       #=> 2007-11-19 08:12:12 -0600
1050
1047
 *     t2 = t + 2592000   #=> 2007-12-19 08:12:12 -0600
2069
2066
static VALUE
2070
2067
time_strftime(VALUE time, VALUE format)
2071
2068
{
 
2069
    void rb_enc_copy(VALUE, VALUE);
2072
2070
    struct time_object *tobj;
2073
2071
    char buffer[SMALLBUF], *buf = buffer;
2074
2072
    const char *fmt;
2080
2078
        time_get_tm(time, tobj->gmt);
2081
2079
    }
2082
2080
    StringValue(format);
 
2081
    if (!rb_enc_str_asciicompat_p(format)) {
 
2082
        rb_raise(rb_eArgError, "format should have ASCII compatible encoding");
 
2083
    }
2083
2084
    format = rb_str_new4(format);
2084
2085
    fmt = RSTRING_PTR(format);
2085
2086
    len = RSTRING_LEN(format);
2109
2110
    }
2110
2111
    str = rb_str_new(buf, len);
2111
2112
    if (buf != buffer) free(buf);
 
2113
    rb_enc_copy(str, format);
2112
2114
    return str;
2113
2115
}
2114
2116
 
2309
2311
 *  stored internally as the number of seconds and nanoseconds since
2310
2312
 *  the <em>Epoch</em>, January 1, 1970 00:00 UTC. On some operating
2311
2313
 *  systems, this offset is allowed to be negative. Also see the
2312
 
 *  library modules <code>Date</code> and <code>ParseDate</code>. The
 
2314
 *  library modules <code>Date</code>. The
2313
2315
 *  <code>Time</code> class treats GMT (Greenwich Mean Time) and UTC
2314
2316
 *  (Coordinated Universal Time)<em>[Yes, UTC really does stand for
2315
2317
 *  Coordinated Universal Time. There was a committee involved.]</em>