summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-23 03:39:25 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-23 03:39:25 +0000
commitaffe49b23b9295ec30d50c363686324038d09158 (patch)
treecce0211c14874887245233ccde6a6ef10ae3d3f3 /time.c
parentf4f0be3a12c4fdba190df790c55805142cf71d1b (diff)
* parse.y (arg): syntaxify tPOW negative number hack.
* parse.y (negate_lit): new function to negate literal numeric values in compile time. * regex.c (re_match_exec): charset info may be stored in MBC region when $KCODE != NONE. * error.c (set_syserr): should preserve duplicated error names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/time.c b/time.c
index b2aee10..310530f 100644
--- a/time.c
+++ b/time.c
@@ -236,11 +236,12 @@ time_arg(argc, argv, tm, usec)
struct tm *tm;
time_t *usec;
{
- VALUE v[7];
+ VALUE v[8];
int i;
long year;
MEMZERO(tm, struct tm, 1);
+ *usec = 0;
if (argc == 10) {
v[0] = argv[5];
v[1] = argv[4];
@@ -248,12 +249,13 @@ time_arg(argc, argv, tm, usec)
v[3] = argv[2];
v[4] = argv[1];
v[5] = argv[0];
- *usec = 0;
tm->tm_isdst = RTEST(argv[8]) ? 1 : 0;
}
else {
- rb_scan_args(argc, argv, "16", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5],&v[6]);
- *usec = NIL_P(v[6]) ? 0 : obj2long(v[6]);
+ rb_scan_args(argc, argv, "17", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5],&v[6],&v[7]);
+ /* v[6] may be usec or zone (parsedate) */
+ /* v[7] is wday (parsedate; ignored) */
+ tm->tm_wday = -1;
tm->tm_isdst = -1;
}
@@ -275,25 +277,28 @@ time_arg(argc, argv, tm, usec)
if (NIL_P(v[1])) {
tm->tm_mon = 0;
}
- else if (TYPE(v[1]) == T_STRING) {
- tm->tm_mon = -1;
- for (i=0; i<12; i++) {
- if (RSTRING(v[1])->len == 3 &&
- strcasecmp(months[i], RSTRING(v[1])->ptr) == 0) {
- tm->tm_mon = i;
- break;
+ else {
+ VALUE s = rb_check_string_type(v[1]);
+ if (!NIL_P(s)) {
+ tm->tm_mon = -1;
+ for (i=0; i<12; i++) {
+ if (RSTRING(s)->len == 3 &&
+ strcasecmp(months[i], RSTRING(v[1])->ptr) == 0) {
+ tm->tm_mon = i;
+ break;
+ }
}
- }
- if (tm->tm_mon == -1) {
- char c = RSTRING(v[1])->ptr[0];
+ if (tm->tm_mon == -1) {
+ char c = RSTRING(s)->ptr[0];
- if ('0' <= c && c <= '9') {
- tm->tm_mon = obj2long(v[1])-1;
+ if ('0' <= c && c <= '9') {
+ tm->tm_mon = obj2long(s)-1;
+ }
}
}
- }
- else {
- tm->tm_mon = obj2long(v[1]) - 1;
+ else {
+ tm->tm_mon = obj2long(v[1])-1;
+ }
}
if (NIL_P(v[2])) {
tm->tm_mday = 1;
@@ -304,6 +309,14 @@ time_arg(argc, argv, tm, usec)
tm->tm_hour = NIL_P(v[3])?0:obj2long(v[3]);
tm->tm_min = NIL_P(v[4])?0:obj2long(v[4]);
tm->tm_sec = NIL_P(v[5])?0:obj2long(v[5]);
+ if (!NIL_P(v[6])) {
+ if (argc == 8) {
+ /* v[6] is timezone, but ignored */
+ }
+ else {
+ *usec = obj2long(v[6]);
+ }
+ }
/* value validation */
if (