Skip to content

Commit

Permalink
Logging datetime according to local timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
0vvland committed Mar 30, 2024
1 parent c752bd1 commit 6495132
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion source/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,24 @@ const Chronos = GObject.registerClass(

this._logOutputStream = file.append_to(Gio.FileCreateFlags.NONE, null);
}
const date = new Date();
const tzo = -date.getTimezoneOffset();
const dif = tzo >= 0 ? '+' : '-';
const pad = function (num) {
return (num < 10 ? '0' : '') + num;
};

const isoDate = date.getFullYear() +
'-' + pad(date.getMonth() + 1) +
'-' + pad(date.getDate()) +
'T' + pad(date.getHours()) +
':' + pad(date.getMinutes()) +
':' + pad(date.getSeconds()) +
dif + pad(Math.floor(Math.abs(tzo) / 60)) +
':' + pad(Math.abs(tzo) % 60);

const bytes = new GLib.Bytes(
`${new Date().toISOString()}: [${event}] ${this.getTrackedTime()}\n`,
`${isoDate}: [${event}] ${this.getTrackedTime()}\n`,
);
this._logOutputStream.write_bytes(bytes, null);
}
Expand Down

0 comments on commit 6495132

Please sign in to comment.