Skip to content

Commit c277645

Browse files
chradekgrs
authored andcommitted
updates timestamp type to accept Date values
1 parent 747ddc0 commit c277645

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/types.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ function write_long(buffer, value, offset) {
256256
}
257257
}
258258

259+
function write_timestamp(buffer, value, offset) {
260+
if (typeof value === 'object' && value !== null && typeof value.getTime === 'function') {
261+
value = value.getTime();
262+
}
263+
return write_long(buffer, value, offset);
264+
}
265+
259266
function read_long(buffer, offset) {
260267
var hi = buffer.readInt32BE(offset);
261268
var lo = buffer.readUInt32BE(offset + 4);
@@ -295,7 +302,7 @@ define_type('Decimal32', 0x74);
295302
define_type('Decimal64', 0x84);
296303
define_type('Decimal128', 0x94);
297304
define_type('CharUTF32', 0x73, buffer_uint32be_ops());
298-
define_type('Timestamp', 0x83, {'write':write_long, 'read':read_timestamp});
305+
define_type('Timestamp', 0x83, {'write':write_timestamp, 'read':read_timestamp});
299306
define_type('Uuid', 0x98);//TODO: convert to/from stringified form?
300307
define_type('Vbin8', 0xa0);
301308
define_type('Vbin32', 0xb0);

test/messages.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ describe('message content', function() {
3434

3535
});
3636

37-
function transfer_test(message: any, verification: Function) {
37+
function transfer_test(message: Partial<rhea.Message>, verification: Function) {
3838
return function(done: Function) {
3939
container.on('message', function(context) {
4040
verification(context.message);
4141
done();
4242
});
43-
sender.send(message);
43+
sender.send(message as any);
4444
};
4545
}
4646

@@ -224,8 +224,8 @@ describe('message content', function() {
224224
correlation_id:'correlate-me',
225225
content_type:'text',
226226
content_encoding:'ascii',
227-
absolute_expiry_time:123456789,
228-
creation_time:987654321,
227+
absolute_expiry_time: new Date(123456789),
228+
creation_time: new Date(987654321),
229229
group_id:'my-group',
230230
group_sequence:77,
231231
reply_to_group_id:'still-my-group',
@@ -275,8 +275,8 @@ describe('message content', function() {
275275
correlation_id:'correlate-me',
276276
content_type:'text',
277277
content_encoding:'ascii',
278-
absolute_expiry_time:123456789,
279-
creation_time:987654321,
278+
absolute_expiry_time: new Date(123456789),
279+
creation_time: new Date(987654321),
280280
group_id:'my-group',
281281
group_sequence:77,
282282
reply_to_group_id:'still-my-group',

0 commit comments

Comments
 (0)