Skip to content

Commit

Permalink
Fixed a bug with invalid release date strings (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Mar 13, 2023
1 parent 45e8fb8 commit 170663d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions js/gameProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,25 @@ function getGameReleaseDate(releaseDateProperty, appInfoDirect, outputProperties
// We need to distinguish three cases: Only the year is given ('2023'), year and month ('March 2023'), or year, month and day ('13 Mar, 2023')
// In cases where data is missing, we add the last day of the year or the first day of the month (as the last day of the month differs between months)
// We always add 00:00 UTC as the time, as the date is always given in UTC and we don't want to convert it to the local timezone
// We wrap this in a try-catch block as developers can set things other than dates, such as 'To be announced', which will raise an error during conversion
try {
const dateSpecificity = appInfoDirect.release_date.date.split(" ").length;
if (dateSpecificity == 1) {
releaseDate = new Date(appInfoDirect.release_date.date + '-12-31 00:00 UTC').toISOString();
} else if (dateSpecificity == 2) {
releaseDate = new Date(appInfoDirect.release_date.date + '-01 00:00 UTC').toISOString();
} else if (dateSpecificity == 3) {
releaseDate = new Date(appInfoDirect.release_date.date + ' 00:00 UTC').toISOString();
} else {
console.warn('!!!The release date format received from the Steam store API is unknown to the integration.\n!!!Please report this to the developer and include the following output:');
console.log(appInfoDirect);
return outputProperties;
}
// We wrap this in a try-catch block as developers can set things other than dates, such as 'To be announced', which will raise an error during conversion
const parsedDate = new Date(appInfoDirect.release_date.date).toISOString();
} catch (error) {
return outputProperties;
}

const dateSpecificity = appInfoDirect.release_date.date.split(" ").length;
if (dateSpecificity == 1) {
releaseDate = new Date(appInfoDirect.release_date.date + '-12-31 00:00 UTC').toISOString();
} else if (dateSpecificity == 2) {
releaseDate = new Date(appInfoDirect.release_date.date + '-01 00:00 UTC').toISOString();
} else if (dateSpecificity == 3) {
releaseDate = new Date(appInfoDirect.release_date.date + ' 00:00 UTC').toISOString();
} else {
console.warn('!!!The release date format received from the Steam store API is unknown to the integration.\n!!!Please report this to the developer and include the following output:');
console.log(appInfoDirect);
return outputProperties;
}
} else {
return outputProperties;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "notion-steam-api-integration",
"type": "module",
"version": "1.5.0",
"version": "1.5.1",
"description": "Notion integration to fetch data from the Steam API and populate a databse given Steam App ID's.",
"main": "index.js",
"dependencies": {
Expand Down

0 comments on commit 170663d

Please sign in to comment.