Skip to content

Commit 1692670

Browse files
authored
Fix the messages datetime (#94)
1 parent 7b6a512 commit 1692670

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/chat-handler.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class ChatHandler extends AbstractChatModel {
112112
id: message.id,
113113
body,
114114
sender: { username: 'User' },
115-
time: Date.now(),
115+
time: Private.getTimestampMs(),
116116
type: 'msg'
117117
};
118118
this.messageAdded(msg);
@@ -122,7 +122,7 @@ export class ChatHandler extends AbstractChatModel {
122122
id: UUID.uuid4(),
123123
body: `**${this._errorMessage ? this._errorMessage : this._defaultErrorMessage}**`,
124124
sender: { username: 'ERROR' },
125-
time: Date.now(),
125+
time: Private.getTimestampMs(),
126126
type: 'msg'
127127
};
128128
this.messageAdded(errorMsg);
@@ -149,7 +149,7 @@ export class ChatHandler extends AbstractChatModel {
149149
id: UUID.uuid4(),
150150
body: '',
151151
sender,
152-
time: Date.now(),
152+
time: Private.getTimestampMs(),
153153
type: 'msg'
154154
};
155155

@@ -173,7 +173,7 @@ export class ChatHandler extends AbstractChatModel {
173173
id: UUID.uuid4(),
174174
body: `**${error}**`,
175175
sender: { username: 'ERROR' },
176-
time: Date.now(),
176+
time: Private.getTimestampMs(),
177177
type: 'msg'
178178
};
179179
this.messageAdded(errorMsg);
@@ -262,3 +262,12 @@ export namespace ChatHandler {
262262
}
263263
}
264264
}
265+
266+
namespace Private {
267+
/**
268+
* Return the current timestamp in milliseconds.
269+
*/
270+
export function getTimestampMs(): number {
271+
return Date.now() / 1000;
272+
}
273+
}

0 commit comments

Comments
 (0)