Пример #1
0
/* 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
/* Creates an instance of time at the given time in local time zone. */
static mrb_value
mrb_time_local(mrb_state *mrb, mrb_value self)
{
  mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0;

  mrb_get_args(mrb, "i|iiiiii",
                &ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
  return mrb_time_wrap(mrb, mrb_class_ptr(self),
          time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL));
}
Пример #3
0
time_t Date::toUtc(const QDateTime &t, const QString &zone)
{
    // Treat empty zone as the current zone
    if (zone.isEmpty())
       return t.toTime_t();

    tm tm;

    QDate date = t.date();
    tm.tm_year = date.year() - 1900;
    tm.tm_mon = date.month() - 1;
    tm.tm_mday = date.day();

    QTime time = t.time();
    tm.tm_hour = time.hour();
    tm.tm_min = time.minute();
    tm.tm_sec = time.second();

    tm.tm_isdst = -1;

    return time_mktime(&tm, zone.toAscii());
}
Пример #4
0
/* 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;
}