1 /***************************** nat/util.c **************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Contains the native functions for class java.util.
9 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
11 Last Change: 1996/11/14
13 *******************************************************************************/
17 /**************************** java.util.Date **********************************/
20 struct java_lang_String* java_util_Date_toString
21 (struct java_util_Date* this)
27 if (!this->valueValid) java_util_Date_computeValue(this);
28 tt = builtin_l2i ( builtin_ldiv(this->value, builtin_i2l(1000) ) );
32 while (l>1 && buffer[l-1]=='\n') l--;
35 return (java_lang_String*) javastring_new_char( buffer );
39 struct java_lang_String* java_util_Date_toLocaleString
40 (struct java_util_Date* this)
46 if (!this->valueValid) java_util_Date_computeValue(this);
47 tt = builtin_l2i ( builtin_ldiv(this->value, builtin_i2l(1000) ) );
49 buffer = asctime (localtime(&tt));
51 while (l>1 && buffer[l-1]=='\n') l--;
54 return (java_lang_String*) javastring_new_char ( buffer );
57 struct java_lang_String* java_util_Date_toGMTString
58 (struct java_util_Date* this)
64 if (!this->valueValid) java_util_Date_computeValue(this);
65 tt = builtin_l2i ( builtin_ldiv(this->value, builtin_i2l(1000) ) );
67 buffer = asctime (gmtime(&tt));
69 while (l>1 && buffer[l-1]=='\n') l--;
73 return (java_lang_String*) javastring_new_char ( buffer );
78 void java_util_Date_expand (struct java_util_Date* this)
83 if (this->expanded) return;
85 tt = builtin_l2i ( builtin_ldiv(this->value, builtin_i2l(1000) ) );
88 builtin_l2i( builtin_lrem (this->value, builtin_i2l(1000) ) );
89 this->tm_sec = t->tm_sec;
90 this->tm_min = t->tm_min;
91 this->tm_hour = t->tm_hour;
92 this->tm_mday = t->tm_mday;
93 this->tm_mon = t->tm_mon;
94 this->tm_wday = t->tm_wday;
95 this->tm_yday = t->tm_yday;
96 this->tm_year = t->tm_year;
97 this->tm_isdst = t->tm_isdst;
101 void java_util_Date_computeValue (struct java_util_Date* this)
105 if (this->valueValid) return;
106 t.tm_sec = this->tm_sec;
107 t.tm_min = this->tm_min;
108 t.tm_hour = this->tm_hour;
109 t.tm_mday = this->tm_mday;
110 t.tm_mon = this->tm_mon;
111 t.tm_wday = this->tm_wday;
112 t.tm_yday = this->tm_yday;
113 t.tm_year = this->tm_year;
114 t.tm_isdst = this->tm_isdst;
117 builtin_lmul( builtin_i2l(mktime(&t)), builtin_i2l(1000)),
118 builtin_i2l(this->tm_millis)
120 this->valueValid = 1;