Class: OraDate

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/oci8/oci8.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

begin

— OraDate.new([year [, month [, day [, hour [, min [,sec]]]]]])

end



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'ext/oci8/oradate.c', line 69

static VALUE ora_date_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE vyear, vmonth, vday, vhour, vmin, vsec;
  ora_date_t *od;
  int year, month, day, hour, min, sec;

  rb_scan_args(argc, argv, "06", &vyear, &vmonth, &vday, &vhour, &vmin, &vsec);
  /* set year */
  if (argc > 0) {
    year = NUM2INT(vyear);
    Check_year(year);
  } else {
    year = 1;
  }
  /* set month */
  if (argc > 1) {
    month = NUM2INT(vmonth);
    Check_month(month);
  } else {
    month = 1;
  }
  /* set day */
  if (argc > 2) {
    day = NUM2INT(vday);
    Check_day(day);
  } else {
    day = 1;
  }
  /* set hour */
  if (argc > 3) {
    hour = NUM2INT(vhour);
    Check_hour(hour);
  } else {
    hour = 0;
  }
  /* set minute */
  if (argc > 4) {
    min = NUM2INT(vmin);
    Check_minute(min);
  } else {
    min = 0;
  }
  /* set second */
  if (argc > 5) {
    sec = NUM2INT(vsec);
    Check_second(sec);
  } else {
    sec = 0;
  }

  Data_Get_Struct(self, ora_date_t, od);
  oci8_set_ora_date(od, year, month, day, hour, min, sec);
  return Qnil;
}

Class Method Details

._load(str) ⇒ Object



346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'ext/oci8/oradate.c', line 346

static VALUE ora_date_s_load(VALUE klass, VALUE str)
{
  ora_date_t *od;
  VALUE obj;

  Check_Type(str, T_STRING);
  if (RSTRING_LEN(str) != sizeof(ora_date_t)) {
    rb_raise(rb_eTypeError, "marshaled OraDate format differ");
  }
  obj = Data_Make_Struct(cOraDate, ora_date_t, NULL, xfree, od);
  memcpy(od, RSTRING_PTR(str), sizeof(ora_date_t));
  return obj;
}

.new(*args) ⇒ Object

ruby 1.6



56
57
58
59
60
61
# File 'ext/oci8/oradate.c', line 56

static VALUE ora_date_s_new(int argc, VALUE *argv, VALUE klass)
{
  VALUE obj = ora_date_s_allocate(klass);
  rb_obj_call_init(obj, argc, argv);
  return obj;
}

.now(*args) ⇒ Object

begin

— OraDate.now()

end



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'ext/oci8/oradate.c', line 152

static VALUE ora_date_s_now(int argc, VALUE *argv)
{
  ora_date_t *od;
  VALUE obj;
  int year, month, day, hour, min, sec;
  time_t tm;
  struct tm *tp;

  tm = time(0);
  tp = localtime(&tm);
  year = tp->tm_year + 1900;
  month = tp->tm_mon + 1;
  day = tp->tm_mday;
  hour = tp->tm_hour;
  min = tp->tm_min;
  sec = tp->tm_sec;

  obj = Data_Make_Struct(cOraDate, ora_date_t, NULL, xfree, od);
  oci8_set_ora_date(od, year, month, day, hour, min, sec);
  return obj;
}

Instance Method Details

#<=>(val) ⇒ Object

begin

— OraDate#<=>(other)

end



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'ext/oci8/oradate.c', line 317

static VALUE ora_date_cmp(VALUE self, VALUE val)
{
  ora_date_t *od1, *od2;
  Data_Get_Struct(self, ora_date_t, od1);
  Data_Get_Struct(val, ora_date_t, od2);
  if (od1->century < od2->century) return INT2FIX(-1);
  if (od1->century > od2->century) return INT2FIX(1);
  if (od1->year < od2->year) return INT2FIX(-1);
  if (od1->year > od2->year) return INT2FIX(1);
  if (od1->month < od2->month) return INT2FIX(-1);
  if (od1->month > od2->month) return INT2FIX(1);
  if (od1->day < od2->day) return INT2FIX(-1);
  if (od1->day > od2->day) return INT2FIX(1);
  if (od1->hour < od2->hour) return INT2FIX(-1);
  if (od1->hour > od2->hour) return INT2FIX(1);
  if (od1->minute < od2->minute) return INT2FIX(-1);
  if (od1->minute > od2->minute) return INT2FIX(1);
  if (od1->second < od2->second) return INT2FIX(-1);
  if (od1->second > od2->second) return INT2FIX(1);
  return INT2FIX(0);
}

#_dump(*args) ⇒ Object



339
340
341
342
343
344
# File 'ext/oci8/oradate.c', line 339

static VALUE ora_date_dump(int argc, VALUE *argv, VALUE self)
{
  ora_date_t *od;
  Data_Get_Struct(self, ora_date_t, od);
  return rb_str_new((const char*)od, sizeof(ora_date_t));
}

#cloneObject

ruby 1.6



140
141
142
143
144
# File 'ext/oci8/oradate.c', line 140

static VALUE ora_date_clone(VALUE self)
{
  VALUE obj = ora_date_s_allocate(CLASS_OF(self));
  return ora_date_initialize_copy(obj, self);
}

#dayObject

#day=Object

#dupObject

ruby 1.6



140
141
142
143
144
# File 'ext/oci8/oradate.c', line 140

static VALUE ora_date_clone(VALUE self)
{
  VALUE obj = ora_date_s_allocate(CLASS_OF(self));
  return ora_date_initialize_copy(obj, self);
}

#hashObject



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'ext/oci8/oradate.c', line 296

static VALUE ora_date_hash(VALUE self)
{
  ora_date_t *od;
  unsigned int v;

  Data_Get_Struct(self, ora_date_t, od);
  v = (od->century <<  8)
    + (od->year    << 15)
    + (od->month   << 22)
    + (od->day     << 26)
    + (od->hour    << 12)
    + (od->minute  <<  6)
    + (od->second  <<  0);
  return INT2FIX(v);
}

#hourObject

#hour=Object

#initialize_copy(rhs) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'ext/oci8/oradate.c', line 124

static VALUE ora_date_initialize_copy(VALUE lhs, VALUE rhs)
{
  ora_date_t *l, *r;

#ifdef HAVE_RB_DEFINE_ALLOC_FUNC
  /* ruby 1.8 */
  rb_obj_init_copy(lhs, rhs);
#endif
  Data_Get_Struct(lhs, ora_date_t, l);
  Data_Get_Struct(rhs, ora_date_t, r);
  memcpy(l, r, sizeof(ora_date_t));
  return lhs;
}

#minuteObject

#minute=Object

#monthObject

#month=Object

#secondObject

#second=Object

#to_aObject

begin

— OraDate#to_a()

end



195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'ext/oci8/oradate.c', line 195

static VALUE ora_date_to_a(VALUE self)
{
  ora_date_t *od;
  VALUE ary[6];
  
  Data_Get_Struct(self, ora_date_t, od);
  ary[0] = INT2FIX(Get_year(od));
  ary[1] = INT2FIX(Get_month(od));
  ary[2] = INT2FIX(Get_day(od));
  ary[3] = INT2FIX(Get_hour(od));
  ary[4] = INT2FIX(Get_minute(od));
  ary[5] = INT2FIX(Get_second(od));
  return rb_ary_new4(6, ary);
}

#to_sObject

begin

— OraDate#to_s()

end



179
180
181
182
183
184
185
186
187
188
# File 'ext/oci8/oradate.c', line 179

static VALUE ora_date_to_s(VALUE self)
{
  ora_date_t *od;
  char buf[30];
  
  Data_Get_Struct(self, ora_date_t, od);
  sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d", Get_year(od), Get_month(od),
	  Get_day(od), Get_hour(od), Get_minute(od), Get_second(od));
  return rb_str_new2(buf);
}

#truncObject

#yearObject

#year=Object