Skip to content

Commit 2bea977

Browse files
authored
samples: corrected eventTime update. (#200)
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> 🦕
1 parent 82ecff4 commit 2bea977

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

retail/interactive-tutorials/setup/update-user-events-json.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ async function main() {
2323

2424
for (let i = 0; i < events.length - 1; ++i) {
2525
const event = JSON.parse(`[${events[i]}]`)[0];
26-
const date = new Date(event.eventTime);
27-
date.setDate(date.getDate() - 1);
26+
let date = new Date(event.eventTime);
27+
const nowDate = new Date();
28+
const timeDiff = nowDate - date;
29+
30+
if (timeDiff > 1000 * 60 * 60 * 24 * 90) {
31+
const yesterday = nowDate - 1000 * 60 * 60 * 24;
32+
date = new Date(yesterday);
33+
}
2834
event.eventTime = date.toISOString();
2935
changedEvents.push(JSON.stringify(event));
3036
}
@@ -37,6 +43,7 @@ async function main() {
3743
stream.write(item + '\n');
3844
});
3945
stream.close();
46+
console.log(`${filePath} is updated`);
4047
};
4148

4249
updateEventsTimestamp('resources/user_events.json');

0 commit comments

Comments
 (0)