Skip to content

Commit

Permalink
Fixed a bug causing future release dates to be converted incorrectly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Mar 13, 2023
1 parent 7e074c4 commit 45e8fb8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 44 deletions.
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ Which game properties should be fetched when a new Steam game is detected, and t
"gameIcon": true,
"releaseDate": {
"enabled": true,
"notionProperty": "Release Date",
"format": "date"
"notionProperty": "Release Date"
},
"reviewScore": {
"enabled": true,
Expand Down Expand Up @@ -277,8 +276,7 @@ The release date of the game. The database field in Notion must be of type "Date
```json
"releaseDate": {
"enabled": true,
"notionProperty": "Release Date",
"format": "date"
"notionProperty": "Release Date"
}
```

Expand All @@ -299,14 +297,6 @@ The name of the Notion property to set the release date in.
| Type | Default value | Possible values | Required |
|---|---|---|---|
| `string` | `"Release Date"` | A valid Notion property name | Yes |

<h4><code>format</code></h4>

The format in which the release date should be set in the database. Can be either "date" or "datetime".

| Type | Default value | Possible values | Required |
|---|---|---|---|
| `string` | `"date"` | `"date"` or `"datetime"` | Yes |
</details>

<details>
Expand Down
3 changes: 1 addition & 2 deletions config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
},
"releaseDate": {
"enabled": true,
"notionProperty": "Release Date",
"format": "date"
"notionProperty": "Release Date"
},
"reviewScore": {
"enabled": true,
Expand Down
18 changes: 3 additions & 15 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
},
"releaseDate": {
"enabled": true,
"notionProperty": "Release Date",
"format": "date"
"notionProperty": "Release Date"
},
"reviewScore": {
"enabled": true,
Expand Down Expand Up @@ -179,8 +178,7 @@
"type": "object",
"default": {
"enabled": true,
"notionProperty": "Release Date",
"format": "date"
"notionProperty": "Release Date"
},
"additionalProperties": false,
"properties": {
Expand All @@ -193,21 +191,11 @@
"description": "The name of the Notion property to set the release date in.",
"type": "string",
"default": "Release Date"
},
"format": {
"description": "The format in which the release date should be set in the database. Can be either \"date\" or \"datetime\".",
"type": "string",
"default": "date",
"enum": [
"date",
"datetime"
]
}
},
"required": [
"enabled",
"notionProperty",
"format"
"notionProperty"
]
},
"reviewScore": {
Expand Down
39 changes: 26 additions & 13 deletions js/gameProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function getGameProperties(appInfoDirect, appInfoSteamUser, steamAp
outputProperties = getGameNameProperty(propertyValue, appInfoSteamUser, outputProperties);
break;
case "releaseDate":
outputProperties = getGameReleaseDate(propertyValue, appInfoSteamUser, outputProperties);
outputProperties = getGameReleaseDate(propertyValue, appInfoDirect, outputProperties);
break;
case "reviewScore":
outputProperties = getGameReviewScore(propertyValue, appInfoSteamUser, outputProperties);
Expand Down Expand Up @@ -108,25 +108,38 @@ function getGameIcon(iconProperty, appInfoSteamUser) {
};
}

function getGameReleaseDate(releaseDateProperty, appInfoSteamUser, outputProperties) {
function getGameReleaseDate(releaseDateProperty, appInfoDirect, outputProperties) {
if (!releaseDateProperty.enabled) { return outputProperties; }

// If no release date is available, don't set it at all in the database
// The releaseDate format from the Steam API is not in ISO format, so we use the SteamUser API instead
// Note: If no release date is available, we don't set it at all in the database
let releaseDate;
if (appInfoSteamUser.original_release_date) {
releaseDate = new Date(parseInt(appInfoSteamUser.original_release_date) * 1000).toISOString();
} else if (appInfoSteamUser.steam_release_date) {
releaseDate = new Date(parseInt(appInfoSteamUser.steam_release_date) * 1000).toISOString();
} else if (appInfoSteamUser.store_asset_mtime) {
releaseDate = new Date(parseInt(appInfoSteamUser.store_asset_mtime) * 1000).toISOString();
if (appInfoDirect.release_date?.date) {
// 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;
}
} catch (error) {
return outputProperties;
}
} else {
return outputProperties;
}

if (releaseDate && releaseDateProperty.format == "date") {
releaseDate = releaseDate.split("T")[0];
}
// We only want the date, not the time, as the store API doesn't provide the time
releaseDate = releaseDate.split("T")[0];

outputProperties[releaseDateProperty.notionProperty] = {
"date": {
Expand Down
2 changes: 1 addition & 1 deletion js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export async function addGameToLocalDatabase(pageId, steamAppId) {
function isStoreAPIRequired() {
return (
CONFIG.gameProperties.coverImage?.enabled ||
CONFIG.gameProperties.releaseDate?.enabled ||
CONFIG.gameProperties.gameDescription?.enabled ||
CONFIG.gameProperties.gamePrice?.enabled
)
Expand All @@ -90,7 +91,6 @@ function isStoreAPIRequired() {
function isSteamUserAPIRequired() {
return (
CONFIG.gameProperties.gameName?.enabled ||
CONFIG.gameProperties.releaseDate?.enabled ||
CONFIG.gameProperties.reviewScore?.enabled ||
CONFIG.gameProperties.tags?.enabled ||
CONFIG.gameProperties.gameIcon?.enabled ||
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.4.0",
"version": "1.5.0",
"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 45e8fb8

Please sign in to comment.