Add time unit suffixes to variables (#561)

Add suffixes like Ms and Ns to variables whos time unit is not in
seconds.  This is aligning with a new code style of putting units
on variables that are not in SI base units.
This commit is contained in:
Hornwitser authored and GitHub committed 2024-01-20 13:26:55 +01:00
1 parent 9842705eb9
commit c53781d16c
38 files changed
+221 -201

No files matched your search

+14 -11
View File
@@ -37,30 +37,33 @@ export default class PlayerStats {
static jsonSchema = Type.Object({
"join_count": Type.Optional(Type.Integer()),
"online_time_ms": Type.Optional(Type.Number()),
"first_join_at": Type.Optional(Type.Number()),
"first_join_at_ms": Type.Optional(Type.Number()),
"last_join_at_ms": Type.Optional(Type.Number()),
"last_leave_at_ms": Type.Optional(Type.Number()),
"last_leave_reason": Type.Optional(Type.String()),
// migrate: renamed fields from alpha 13
"last_join_at": Type.Optional(Type.Number()),
"last_leave_at": Type.Optional(Type.Number()),
"last_leave_reason": Type.Optional(Type.String()),
});
constructor(json: Static<typeof PlayerStats.jsonSchema> = {}) {
if (json["join_count"]) {
this.joinCount = json["join_count"];
}
if (json["first_join_at"]) {
this.firstJoinAt = new Date(json["first_join_at"]);
if (json["first_join_at_ms"]) {
this.firstJoinAt = new Date(json["first_join_at_ms"]);
}
if (json["online_time_ms"]) {
this.onlineTimeMs = json["online_time_ms"];
}
if (json["last_join_at"]) {
this.lastJoinAt = new Date(json["last_join_at"]);
if (json["last_join_at_ms"] ?? json["last_join_at"]) {
this.lastJoinAt = new Date(json["last_join_at_ms"] ?? json["last_join_at"]!);
if (!this.firstJoinAt) { // migrate: pre-alpha 14 did not have this field.
this.firstJoinAt = this.lastJoinAt;
}
}
if (json["last_leave_at"]) {
this.lastLeaveAt = new Date(json["last_leave_at"]);
if (json["last_leave_at_ms"] ?? json["last_leave_at"]) {
this.lastLeaveAt = new Date(json["last_leave_at_ms"] ?? json["last_leave_at"]!);
this.lastLeaveReason = json["last_leave_reason"] || "quit";
}
}
@@ -78,13 +81,13 @@ export default class PlayerStats {
json["online_time_ms"] = this.onlineTimeMs;
}
if (this.firstJoinAt) {
json["first_join_at"] = this.firstJoinAt.getTime();
json["first_join_at_ms"] = this.firstJoinAt.getTime();
}
if (this.lastJoinAt) {
json["last_join_at"] = this.lastJoinAt.getTime();
json["last_join_at_ms"] = this.lastJoinAt.getTime();
}
if (this.lastLeaveAt) {
json["last_leave_at"] = this.lastLeaveAt.getTime();
json["last_leave_at_ms"] = this.lastLeaveAt.getTime();
json["last_leave_reason"] = this.lastLeaveReason;
}
return json;