diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-06 01:41:37 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-06 01:41:37 +0900 |
| commit | 9dfdbe66321523863acd0f5fd067dc320f4ee535 (patch) | |
| tree | 02ea67879874dd8374e862fc85599b0faa8dc217 /mrbgems/mruby-time | |
| parent | 2f20463b7746aefd7d5334166590bb633753ccdd (diff) | |
| parent | 69b231ece5fff7fe0c4c97514fc1bdd8150b714a (diff) | |
| download | mruby-9dfdbe66321523863acd0f5fd067dc320f4ee535.tar.gz mruby-9dfdbe66321523863acd0f5fd067dc320f4ee535.zip | |
Merge pull request #1813 from cremno/time-1
mruby-time: various smaller changes
Diffstat (limited to 'mrbgems/mruby-time')
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 2e72c5c53..9cf7c2fd7 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -4,10 +4,9 @@ ** See Copyright Notice in mruby.h */ - -#include "mruby.h" #include <stdio.h> #include <time.h> +#include "mruby.h" #include "mruby/class.h" #include "mruby/data.h" @@ -35,7 +34,7 @@ #endif /* timegm(3) */ -/* mktime() creates tm structure for localtime; timegm() is for UTF time */ +/* mktime() creates tm structure for localtime; timegm() is for UTC time */ /* define following macro to use probably faster timegm() on the platform */ /* #define USE_SYSTEM_TIMEGM */ @@ -81,7 +80,7 @@ timegm(struct tm *tm) } #endif -/* Since we are limited to using ISO C89, this implementation is based +/* Since we are limited to using ISO C99, this implementation is based * on time_t. That means the resolution of time is only precise to the * second level. Also, there are only 2 timezones, namely UTC and LOCAL. */ @@ -94,22 +93,21 @@ enum mrb_timezone { }; typedef struct mrb_timezone_name { - const char *name; + const char name[8]; size_t len; } mrb_timezone_name; -static mrb_timezone_name timezone_names[] = { +static const mrb_timezone_name timezone_names[] = { { "none", sizeof("none") - 1 }, - { "UTC", sizeof("UTC") - 1 }, + { "UTC", sizeof("UTC") - 1 }, { "LOCAL", sizeof("LOCAL") - 1 }, - { NULL, 0 } }; -static const char *mon_names[] = { +static const char mon_names[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }; -static const char *wday_names[] = { +static const char wday_names[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", }; @@ -120,7 +118,7 @@ struct mrb_time { struct tm datetime; }; -static struct mrb_data_type mrb_time_type = { "Time", mrb_free }; +static const struct mrb_data_type mrb_time_type = { "Time", mrb_free }; /** Updates the datetime of a mrb_time based on it's timezone and seconds setting. Returns self on success, NULL of failure. */ @@ -406,7 +404,7 @@ mrb_time_zone(mrb_state *mrb, mrb_value self) tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time); if (tm->timezone <= MRB_TIMEZONE_NONE) return mrb_nil_value(); if (tm->timezone >= MRB_TIMEZONE_LAST) return mrb_nil_value(); - return mrb_str_new_static(mrb, + return mrb_str_new_static(mrb, timezone_names[tm->timezone].name, timezone_names[tm->timezone].len); } @@ -424,10 +422,10 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self) tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time); d = &tm->datetime; len = snprintf(buf, sizeof(buf), "%s %s %02d %02d:%02d:%02d %s%d", - wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday, - d->tm_hour, d->tm_min, d->tm_sec, - tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "", - d->tm_year + 1900); + wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday, + d->tm_hour, d->tm_min, d->tm_sec, + tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "", + d->tm_year + 1900); return mrb_str_new(mrb, buf, len); } |
