@@ -4,6 +4,10 @@ use core::cmp::Eq;
4
4
use libc:: { c_char, c_int, c_long, size_t, time_t} ;
5
5
use io:: { Reader , ReaderUtil } ;
6
6
use result:: { Result , Ok , Err } ;
7
+ use serialization:: { Serializable ,
8
+ Deserializable ,
9
+ Serializer ,
10
+ Deserializer } ;
7
11
8
12
#[ abi = "cdecl" ]
9
13
extern mod rustrt {
@@ -75,20 +79,60 @@ pub fn tzset() {
75
79
rustrt:: rust_tzset ( ) ;
76
80
}
77
81
78
- type Tm_ = {
79
- tm_sec : i32 , // seconds after the minute ~[0-60]
80
- tm_min : i32 , // minutes after the hour ~[0-59]
81
- tm_hour : i32 , // hours after midnight ~[0-23]
82
- tm_mday : i32 , // days of the month ~[1-31]
83
- tm_mon : i32 , // months since January ~[0-11]
84
- tm_year : i32 , // years since 1900
85
- tm_wday : i32 , // days since Sunday ~[0-6]
86
- tm_yday : i32 , // days since January 1 ~[0-365]
87
- tm_isdst : i32 , // Daylight Savings Time flag
88
- tm_gmtoff : i32 , // offset from UTC in seconds
89
- tm_zone : ~str , // timezone abbreviation
90
- tm_nsec : i32 , // nanoseconds
91
- } ;
82
+ pub struct Tm_ {
83
+ pub tm_sec : i32 , // seconds after the minute ~[0-60]
84
+ pub tm_min : i32 , // minutes after the hour ~[0-59]
85
+ pub tm_hour : i32 , // hours after midnight ~[0-23]
86
+ pub tm_mday : i32 , // days of the month ~[1-31]
87
+ pub tm_mon : i32 , // months since January ~[0-11]
88
+ pub tm_year : i32 , // years since 1900
89
+ pub tm_wday : i32 , // days since Sunday ~[0-6]
90
+ pub tm_yday : i32 , // days since January 1 ~[0-365]
91
+ pub tm_isdst : i32 , // Daylight Savings Time flag
92
+ pub tm_gmtoff : i32 , // offset from UTC in seconds
93
+ pub tm_zone : ~str , // timezone abbreviation
94
+ pub tm_nsec : i32 , // nanoseconds
95
+ }
96
+
97
+ impl < S : Serializer > Tm_ : Serializable < S > {
98
+ fn serialize ( & self , s : & S ) {
99
+ s. emit_i32 ( self . tm_sec ) ;
100
+ s. emit_i32 ( self . tm_min ) ;
101
+ s. emit_i32 ( self . tm_hour ) ;
102
+ s. emit_i32 ( self . tm_mday ) ;
103
+ s. emit_i32 ( self . tm_mon ) ;
104
+ s. emit_i32 ( self . tm_year ) ;
105
+ s. emit_i32 ( self . tm_wday ) ;
106
+ s. emit_i32 ( self . tm_yday ) ;
107
+ s. emit_i32 ( self . tm_isdst ) ;
108
+ s. emit_i32 ( self . tm_gmtoff ) ;
109
+ s. emit_owned_str ( self . tm_zone ) ;
110
+ s. emit_i32 ( self . tm_nsec ) ;
111
+ }
112
+ }
113
+
114
+ pub fn deserialize_tm_ < D : Deserializer > ( d : & D ) -> Tm_ {
115
+ Tm_ {
116
+ tm_sec : d. read_i32 ( ) ,
117
+ tm_min : d. read_i32 ( ) ,
118
+ tm_hour : d. read_i32 ( ) ,
119
+ tm_mday : d. read_i32 ( ) ,
120
+ tm_mon : d. read_i32 ( ) ,
121
+ tm_year : d. read_i32 ( ) ,
122
+ tm_wday : d. read_i32 ( ) ,
123
+ tm_yday : d. read_i32 ( ) ,
124
+ tm_isdst : d. read_i32 ( ) ,
125
+ tm_gmtoff : d. read_i32 ( ) ,
126
+ tm_zone : d. read_owned_str ( ) ,
127
+ tm_nsec : d. read_i32 ( ) ,
128
+ }
129
+ }
130
+
131
+ impl < D : Deserializer > Tm_ : Deserializable < D > {
132
+ static fn deserialize( d : & D ) -> Tm_ {
133
+ deserialize_tm_( d )
134
+ }
135
+ }
92
136
93
137
impl Tm_ : Eq {
94
138
#[ cfg( stage0) ]
@@ -133,6 +177,23 @@ pub enum Tm {
133
177
Tm_ ( Tm_ )
134
178
}
135
179
180
+ impl < S : Serializer > Tm : Serializable < S > {
181
+ fn serialize ( & self , s : & S ) {
182
+ let t: Tm_ = * * self ;
183
+ t. serialize ( s) ;
184
+ }
185
+ }
186
+
187
+ pub fn deserialize_tm < D : Deserializer > ( d : & D ) -> Tm {
188
+ Tm_ ( deserialize_tm_ ( d) )
189
+ }
190
+
191
+ impl < D : Deserializer > Tm : Deserializable < D > {
192
+ static fn deserialize( d : & D ) -> Tm {
193
+ deserialize_tm( d )
194
+ }
195
+ }
196
+
136
197
impl Tm : Eq {
137
198
#[ cfg( stage0) ]
138
199
pure fn eq ( other : & Tm ) -> bool { * self == * ( * other) }
@@ -147,7 +208,7 @@ impl Tm : Eq {
147
208
}
148
209
149
210
pub pure fn empty_tm ( ) -> Tm {
150
- Tm_ ( {
211
+ Tm_ ( Tm_ {
151
212
tm_sec : 0_i32 ,
152
213
tm_min : 0_i32 ,
153
214
tm_hour : 0_i32 ,
@@ -652,7 +713,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
652
713
}
653
714
654
715
do io:: with_str_reader ( str:: from_slice ( format) ) |rdr| {
655
- let mut tm = {
716
+ let mut tm = Tm_ {
656
717
tm_sec : 0_i32 ,
657
718
tm_min : 0_i32 ,
658
719
tm_hour : 0_i32 ,
@@ -686,7 +747,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
686
747
}
687
748
688
749
if pos == len && rdr. eof ( ) {
689
- Ok ( Tm_ ( {
750
+ Ok ( Tm_ ( Tm_ {
690
751
tm_sec : tm. tm_sec ,
691
752
tm_min : tm. tm_min ,
692
753
tm_hour : tm. tm_hour ,
0 commit comments