fix timezone for publish date mutation (#149)

This commit is contained in:
Anders Gustafsson
2023-03-27 11:08:52 +02:00
committed by GitHub
parent c66a18478b
commit 88fc6f67f1
3 changed files with 14 additions and 11 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ ENV NEW_RELIC_NO_CONFIG_FILE=true
# Installs npm dependencies on container # Installs npm dependencies on container
RUN npm ci RUN npm ci
# Command container will actually run when called # Command container will actually run when called
CMD ["npx", "nodemon", "-w", "src", "--ext", "ts", "--exec", "ts-node", "src/index.ts"] CMD ["npx", "nodemon", "-w", "src", "--ext", "ts", "--exec", "TZ=Europe/Paris", "ts-node", "src/index.ts"]
+1 -1
View File
@@ -9,4 +9,4 @@ WORKDIR /app
ENV NODE_ENV=development ENV NODE_ENV=development
ENV NEW_RELIC_NO_CONFIG_FILE=true ENV NEW_RELIC_NO_CONFIG_FILE=true
# Command container will actually run when called # Command container will actually run when called
CMD ["npx", "nodemon", "-w", "src", "--ext", "ts", "--exec", "ts-node", "src/index.ts"] CMD ["npx", "nodemon", "-w", "src", "--ext", "ts", "--exec", "TZ=Europe/Paris", "ts-node", "src/index.ts"]
+12 -9
View File
@@ -537,15 +537,18 @@ export class ProductAPI extends BaseSQLDataSource {
promises.push(promise); promises.push(promise);
} }
const pd = info.publishingDate; const publishingDate = info.publishingDate;
const publishingDate = new Date( // Some notes about timezone here:
pd.getFullYear(), // If client sets YYYY-MM-10T00:00:00.000+02 (which admin does) the timestamp
pd.getMonth(), // here will be YYYY-MM-09T22:00:00.000Z since JS internal Dates are always in UTC and will be
pd.getDate(), // sent like the string above from client to graphql server.
0, // Some functions on the Date object however is local timezone dependent. setHours is one of them.
0, // So as long as we correctly set timezone for node to be Europe/Paris to match
0, // database server the publishDate above (in UTC) can be YYYY-MM-09T22:00:00.000Z and setHours will not (incorrectly)
); // set it to YYYY-MM-09T00:00:00.000Z but but instead keep it as YYYY-MM-09T22:00:00.000Z since that is hour, minute
// second 0 of YYYY-MM-10 with the local timezone.
publishingDate.setHours(0, 0, 0);
promises.push( promises.push(
this.knex this.knex
.table('product-products') .table('product-products')