Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(isDate): Enhance Date declaration compatibility across multiple environments #2231

Merged
merged 5 commits into from
Jun 12, 2023

Conversation

CiprianS
Copy link
Contributor

@CiprianS CiprianS commented Jun 6, 2023

feat(isDate): Enhance Date declaration compatibility across multiple environments

The issue occurred with the date declaration in the React Native - Android environment, specifically when using the following format:
new Date(${dateObj.m}/${dateObj.d}/${dateObj.y}).getDate() === +dateObj.d;

In JavaScript, the Date constructor parses a string argument in a platform-dependent way, and it may not parse the string identically across different environments, such as various browsers or operating systems. The date format ('mm/dd/yyyy') used in the current code is very U.S.-centric and isn't guaranteed to work consistently across all systems or locales.

According to the ECMAScript specification, the only string format required to be parsed accurately across all platforms is a variant of the ISO 8601 format: 'YYYY-MM-DDTHH:mm:ss.sssZ'. Any other format may produce inconsistent results, depending on the system's implementation.

In scenarios where the year is represented with two digits (e.g., 95, 00, 18), we have introduced a check to correctly prepend it with either '20' or '19', thus maintaining accuracy and compatibility.

This enhancement aims to increase the reliability of the isDate feature across multiple environments and bring the codebase closer to established standards.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Patch coverage: 80.00% and project coverage change: -0.09 ⚠️

Comparison is base (9ba1735) 99.95% compared to head (af7e403) 99.87%.

❗ Current head af7e403 differs from pull request most recent head 81d78d5. Consider uploading reports for the commit 81d78d5 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2231      +/-   ##
==========================================
- Coverage   99.95%   99.87%   -0.09%     
==========================================
  Files         107      107              
  Lines        2405     2414       +9     
  Branches      604      607       +3     
==========================================
+ Hits         2404     2411       +7     
- Misses          0        1       +1     
- Partials        1        2       +1     
Impacted Files Coverage Δ
src/lib/isDate.js 95.00% <80.00%> (-5.00%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@StanislavSava
Copy link

@chriso @profnandaa Can you please take a look at this PR? It's pretty small but with a big impact, validation is broken in multiple places for React Native - Android env due to this

@profnandaa
Copy link
Member

profnandaa commented Jun 7, 2023 via email

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the contrib! 🎉

@profnandaa profnandaa merged commit df1351a into validatorjs:master Jun 12, 2023
@CiprianS
Copy link
Contributor Author

CiprianS commented Jul 3, 2023

@profnandaa We've noticed that the latest changes haven't been published yet. Our project relies heavily on these updates, and we are eagerly waiting to integrate them. Could you provide an estimate on when we can expect the new version to be published? It would greatly assist us in planning our development process. Thank you.

@tomaspanek tomaspanek mentioned this pull request Aug 5, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants