Skip to content

Commit

Permalink
remove offset
Browse files Browse the repository at this point in the history
  • Loading branch information
zongqichen committed Dec 9, 2024
1 parent 0f9b83f commit a2931c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
5 changes: 0 additions & 5 deletions __tests__/unittest/date.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ describe('date', () => {
expect(lastUpdate).toMatch(RFC3339_REGEX);
});

it('tests getRFC3339Date without offset', () => {
const lastUpdate = getRFC3339Date(false);
expect(lastUpdate).toMatch(RFC3339_REGEX);
});

it('test regex correctly', () => {
let lastUpdate = "1985-04-12T23:20:50.52Z";
expect(lastUpdate).toMatch(RFC3339_REGEX);
Expand Down
15 changes: 5 additions & 10 deletions lib/date.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
function getRFC3339Date(includeOffset = true) {
function getRFC3339Date() {
const now = new Date();
const year = now.getUTCFullYear();
const month = String(now.getUTCMonth() + 1).padStart(2, '0');
const day = String(now.getUTCDate()).padStart(2, '0');
const hours = String(now.getUTCHours()).padStart(2, '0');
const minutes = String(now.getUTCMinutes()).padStart(2, '0');
const seconds = String(now.getUTCSeconds()).padStart(2, '0');

if (includeOffset) {
const offsetHours = '01';
const offsetMinutes = '00';
const offsetSign = '+';
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${offsetSign}${offsetHours}:${offsetMinutes}`;
} else {
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z`;
}
const offsetHours = '01';
const offsetMinutes = '00';
const offsetSign = '+';
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${offsetSign}${offsetHours}:${offsetMinutes}`;
}

module.exports = {
Expand Down

0 comments on commit a2931c5

Please sign in to comment.