コード例 #1
0
ファイル: time.c プロジェクト: Asmod4n/mruby
/* Initializes a time by setting the amount of milliseconds since the epoch.*/
static mrb_value
mrb_time_initialize(mrb_state *mrb, mrb_value self)
{
  mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0,
  amin = 0, asec = 0, ausec = 0;
  int n;
  struct mrb_time *tm;

  tm = (struct mrb_time*)DATA_PTR(self);
  if (tm) {
    mrb_free(mrb, tm);
  }
  mrb_data_init(self, NULL, &mrb_time_type);

  n = mrb_get_args(mrb, "|iiiiiii",
       &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
  if (n == 0) {
    tm = current_mrb_time(mrb);
  }
  else {
    tm = time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL);
  }
  mrb_data_init(self, tm, &mrb_time_type);
  return self;
}
コード例 #2
0
ファイル: time.c プロジェクト: katsuyuki-nakamura/mruby
/* Initializes a time by setting the amount of milliseconds since the epoch.*/
static mrb_value
mrb_time_initialize(mrb_state *mrb, mrb_value self)
{
  mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, 
  amin = 0, asec = 0, ausec = 0;
  struct mrb_time *tm;

  tm = mrb_get_datatype(mrb, self, &mrb_time_type);
  if (tm) {
    mrb_time_free(mrb, tm);
  }
  if (mrb->ci->argc == 0) {
    tm = current_mrb_time(mrb);
  }
  else {
    mrb_get_args(mrb, "iiiiiii",
		 &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
    tm = time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL);
  }
  DATA_PTR(self) = tm;
  DATA_TYPE(self) = &mrb_time_type;
  return self;
}
コード例 #3
0
ファイル: time.c プロジェクト: Asmod4n/mruby
/* Allocates a new Time object with given millis value. */
static mrb_value
mrb_time_now(mrb_state *mrb, mrb_value self)
{
  return mrb_time_wrap(mrb, mrb_class_ptr(self), current_mrb_time(mrb));
}