jaktestowac / gad-gui-api-demo

GAD🦎 - Application for learning testing GUI and API
https://jaktestowac.pl/about-gad
GNU General Public License v3.0
14 stars 10 forks source link

[Bug] Date validation throws error after switching to daylight saving time #18

Closed baciek-pl closed 6 months ago

baciek-pl commented 7 months ago

Hi, There's an issue with adding articles when app is deployed in Glitch.

Steps to reproduce

  1. Log in & navigate to the Add Article page
  2. Fill in title and body
  3. Click "Save"

Expected result Article is saved

Actual result Error "Article was not saved" is displayed. When you open network tab from the developer tools, you can see 422 error with the message: {"error":{"message":"Date field is invalid: Field validation: \"date\" has date in future!","details":["date"]}}

After some digging, I found the issue is with the following function:

function isDateInFuture(dateString) {
  const inputDate = new Date(dateString);
  const currentDate = new Date();

  currentDate.setHours(currentDate.getHours() + 1); // UTC+1

  currentDate.setSeconds(currentDate.getSeconds() + 10); // add possibility of offset
  logTrace("isDateInFuture:", { inputDate, currentDate });

  if (isBugEnabled(BugConfigKeys.BUG_VALIDATION_007)) {
    return true;
  }
  if (isBugEnabled(BugConfigKeys.BUG_VALIDATION_008)) {
    return false;
  }

  return inputDate > currentDate;

Issue was resolved after changing the code to:

function isDateInFuture(dateString) {
  const inputDate = new Date(dateString);
  const currentDate = new Date();

  currentDate.setHours(currentDate.getHours() + 2); // UTC+2

  currentDate.setSeconds(currentDate.getSeconds() + 10); // add possibility of offset
  logTrace("isDateInFuture:", { inputDate, currentDate });

  if (isBugEnabled(BugConfigKeys.BUG_VALIDATION_007)) {
    return true;
  }
  if (isBugEnabled(BugConfigKeys.BUG_VALIDATION_008)) {
    return false;
  }

  return inputDate > currentDate;
Freudenberger commented 7 months ago

Hello! @baciek-pl thank You for reported issue :) I introduce fix for daylight saving time in latest release https://github.com/jaktestowac/gad-gui-api-demo/releases/tag/v2.6.0

Please verify if that solves also Your case :)

Freudenberger commented 6 months ago

While bug does not seem to be re-reported - closing.