Skip to content

Commit

Permalink
samples: corrected eventTime update. (#200)
Browse files Browse the repository at this point in the history
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-retail/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕
  • Loading branch information
Arakel2811 authored Aug 2, 2022
1 parent 82ecff4 commit 2bea977
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions retail/interactive-tutorials/setup/update-user-events-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ async function main() {

for (let i = 0; i < events.length - 1; ++i) {
const event = JSON.parse(`[${events[i]}]`)[0];
const date = new Date(event.eventTime);
date.setDate(date.getDate() - 1);
let date = new Date(event.eventTime);
const nowDate = new Date();
const timeDiff = nowDate - date;

if (timeDiff > 1000 * 60 * 60 * 24 * 90) {
const yesterday = nowDate - 1000 * 60 * 60 * 24;
date = new Date(yesterday);
}
event.eventTime = date.toISOString();
changedEvents.push(JSON.stringify(event));
}
Expand All @@ -37,6 +43,7 @@ async function main() {
stream.write(item + '\n');
});
stream.close();
console.log(`${filePath} is updated`);
};

updateEventsTimestamp('resources/user_events.json');
Expand Down

0 comments on commit 2bea977

Please sign in to comment.