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

O3-2476 - isOmrsDateStrict should accept dates with negative timezone… #785

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

mseaton
Copy link
Member

@mseaton mseaton commented Oct 6, 2023

… offsets

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.

If applicable

  • My work includes tests or is validated by existing tests.

Related Issue

https://issues.openmrs.org/browse/O3-2476

@@ -50,7 +50,7 @@ export function isOmrsDateStrict(omrsPayloadString: string): boolean {
}

// checking UTC offset format
if (!(omrsPayloadString[23] === "+" && omrsPayloadString[26] !== ":")) {
if (!(omrsPayloadString[23] === "+" || omrsPayloadString[23] === "-")) {
Copy link
Member Author

@mseaton mseaton Oct 6, 2023

Choose a reason for hiding this comment

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

So, I don't know what that original omrsPayloadString[26] !== ":" was all about, it's not documented, and I don't really understand the use case, and all of the unit tests pass without it being there, so I removed it in addition to allowing the negative offset...

Copy link
Member

Choose a reason for hiding this comment

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

Zone formats are specified like +05:00 or -05:00 so it's checking both there's a +, two characters, and a colon.

Copy link
Member

@ibacher ibacher Oct 6, 2023

Choose a reason for hiding this comment

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

This should work and be consistent with the code here that verifies all the non-numeric components:

Suggested change
if (!(omrsPayloadString[23] === "+" || omrsPayloadString[23] === "-")) {
if (!(omrsPayloadString[23] === "+" || omrsPayloadString[23] === "-" || omrsPayloadString[26] === ":")) {

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so @ibacher ? Look at all of the test cases for this class, and look at the date string I was originally having an issue with on the ticket. It's in the format: 2023-10-06T12:56:56.065-0400. There is no colon in the TZ offset...

Copy link
Member Author

Choose a reason for hiding this comment

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

Specifically @ibacher, the isoFormat specified in omrs-dates.js is:

const isoFormat = "YYYY-MM-DDTHH:mm:ss.SSSZZ";

And, per the day.js documentation, "ZZ" is "compact offset from UTC", whereas just "Z" is the offset with the ":". See https://day.js.org/docs/en/parse/string-format. So with our date format, we will get "-0500", not "-05:00".

Copy link
Member

Choose a reason for hiding this comment

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

It looks like ISO considers both including and not including a : as valid (https://en.wikipedia.org/wiki/ISO_8601)

I can't remember where, but I do remember some case where we were having an issue with this... ie like an old version of Java only excepted one of the two?

Do note @ibacher that it looks like the initial code was testing that a colon was not present, so it was enforcing the "0400" format. I'm fine with removing it.... though see my comment above.

Also will flag @brandones @FlorianRappl in case they have any insight.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I misread that!

Copy link
Member Author

Choose a reason for hiding this comment

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

In any event, removing the check on : only serves to make the code more permissive, not less permissive. And the unit test that checks this still works regardless, which presumably is because later on, we return dayjs(omrsPayloadString, isoFormat).isValid() with our isoFormat of "YYYY-MM-DDTHH:mm:ss.SSSZZ". So there isn't any need for us to have this additional custom check anyway.

Copy link
Collaborator

@brandones brandones Oct 10, 2023

Choose a reason for hiding this comment

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

Yeah I assume there only is such a thing as "omrs ISO format" because, again I assume, the OpenMRS server must use an ISO parser that is not quite correct; perhaps it is more particular about format than the ISO spec. If the OpenMRS server understands any ISO-spec date strings than I don't know why any of those functions exist. I did not implement them, so I don't really know what the motivation was.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @brandones ... this rang a bell and I was actually able to track this down, see bug here:

https://issues.openmrs.org/browse/RESTWS-419?jql=project%20%3D%20RESTWS%20AND%20text%20~%20%22date%22

However, this assumedly was resolved years ago?

Note that even though @mseaton removed the test for the colon in the timezone, such a string is still considered invaid, I believe/assume because it's 29 characters in length instead of 28, and that is one of the first checks in the validator... fyi @ibacher @mseaton

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2023

Size Change: -327 kB (-10%) 👏

Total Size: 2.82 MB

Filename Size Change
packages/shell/esm-app-shell/dist/openmrs.80d3c301782cf733.js 0 B -327 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
packages/apps/esm-devtools-app/dist/68.js 4.29 kB 0 B
packages/apps/esm-devtools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-devtools-app/dist/889.js 172 kB +4 B (0%)
packages/apps/esm-devtools-app/dist/988.js 282 B 0 B
packages/apps/esm-devtools-app/dist/main.js 2.95 kB 0 B
packages/apps/esm-devtools-app/dist/openmrs-esm-devtools-app.js 3.03 kB 0 B
packages/apps/esm-implementer-tools-app/dist/220.js 4.43 kB 0 B
packages/apps/esm-implementer-tools-app/dist/246.js 449 B 0 B
packages/apps/esm-implementer-tools-app/dist/263.js 6.66 kB 0 B
packages/apps/esm-implementer-tools-app/dist/319.js 633 B 0 B
packages/apps/esm-implementer-tools-app/dist/329.js 10 kB 0 B
packages/apps/esm-implementer-tools-app/dist/426.js 1.66 kB 0 B
packages/apps/esm-implementer-tools-app/dist/466.js 5.85 kB 0 B
packages/apps/esm-implementer-tools-app/dist/499.js 2.87 kB 0 B
packages/apps/esm-implementer-tools-app/dist/500.js 2.83 kB 0 B
packages/apps/esm-implementer-tools-app/dist/519.js 400 B 0 B
packages/apps/esm-implementer-tools-app/dist/56.js 3.07 kB 0 B
packages/apps/esm-implementer-tools-app/dist/574.js 560 B 0 B
packages/apps/esm-implementer-tools-app/dist/575.js 713 B 0 B
packages/apps/esm-implementer-tools-app/dist/587.js 2.81 kB 0 B
packages/apps/esm-implementer-tools-app/dist/620.js 126 kB 0 B
packages/apps/esm-implementer-tools-app/dist/625.js 562 B 0 B
packages/apps/esm-implementer-tools-app/dist/640.js 32.8 kB 0 B
packages/apps/esm-implementer-tools-app/dist/657.js 562 B 0 B
packages/apps/esm-implementer-tools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-implementer-tools-app/dist/757.js 560 B 0 B
packages/apps/esm-implementer-tools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-implementer-tools-app/dist/807.js 1.44 kB 0 B
packages/apps/esm-implementer-tools-app/dist/833.js 681 B 0 B
packages/apps/esm-implementer-tools-app/dist/837.js 55.1 kB 0 B
packages/apps/esm-implementer-tools-app/dist/889.js 172 kB +5 B (0%)
packages/apps/esm-implementer-tools-app/dist/main.js 4.17 kB 0 B
packages/apps/esm-implementer-tools-app/dist/openmrs-esm-implementer-tools-app.js 3.31 kB 0 B
packages/apps/esm-login-app/dist/111.js 1.22 kB 0 B
packages/apps/esm-login-app/dist/126.js 2.5 kB 0 B
packages/apps/esm-login-app/dist/144.js 21.7 kB 0 B
packages/apps/esm-login-app/dist/173.js 1.22 kB 0 B
packages/apps/esm-login-app/dist/236.js 272 B 0 B
packages/apps/esm-login-app/dist/240.js 364 B 0 B
packages/apps/esm-login-app/dist/261.js 6.28 kB 0 B
packages/apps/esm-login-app/dist/263.js 6.65 kB 0 B
packages/apps/esm-login-app/dist/272.js 264 B 0 B
packages/apps/esm-login-app/dist/319.js 504 B 0 B
packages/apps/esm-login-app/dist/336.js 234 B 0 B
packages/apps/esm-login-app/dist/337.js 1.3 kB 0 B
packages/apps/esm-login-app/dist/342.js 11.6 kB 0 B
packages/apps/esm-login-app/dist/539.js 298 B 0 B
packages/apps/esm-login-app/dist/56.js 3.06 kB 0 B
packages/apps/esm-login-app/dist/574.js 428 B 0 B
packages/apps/esm-login-app/dist/610.js 5.84 kB 0 B
packages/apps/esm-login-app/dist/625.js 421 B 0 B
packages/apps/esm-login-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-login-app/dist/644.js 305 B 0 B
packages/apps/esm-login-app/dist/673.js 284 B 0 B
packages/apps/esm-login-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-login-app/dist/757.js 509 B 0 B
packages/apps/esm-login-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-login-app/dist/807.js 685 B 0 B
packages/apps/esm-login-app/dist/829.js 10.2 kB 0 B
packages/apps/esm-login-app/dist/833.js 528 B 0 B
packages/apps/esm-login-app/dist/889.js 172 kB +6 B (0%)
packages/apps/esm-login-app/dist/967.js 576 B 0 B
packages/apps/esm-login-app/dist/main.js 3.59 kB 0 B
packages/apps/esm-login-app/dist/openmrs-esm-login-app.js 3.28 kB 0 B
packages/apps/esm-offline-tools-app/dist/202.js 9.73 kB 0 B
packages/apps/esm-offline-tools-app/dist/206.js 7.41 kB 0 B
packages/apps/esm-offline-tools-app/dist/224.js 3.86 kB 0 B
packages/apps/esm-offline-tools-app/dist/263.js 6.66 kB 0 B
packages/apps/esm-offline-tools-app/dist/273.js 48.9 kB 0 B
packages/apps/esm-offline-tools-app/dist/281.js 16.3 kB 0 B
packages/apps/esm-offline-tools-app/dist/297.js 466 B 0 B
packages/apps/esm-offline-tools-app/dist/316.js 2.04 kB 0 B
packages/apps/esm-offline-tools-app/dist/319.js 1.14 kB 0 B
packages/apps/esm-offline-tools-app/dist/391.js 305 B 0 B
packages/apps/esm-offline-tools-app/dist/412.js 1.58 kB 0 B
packages/apps/esm-offline-tools-app/dist/47.js 6.34 kB 0 B
packages/apps/esm-offline-tools-app/dist/501.js 24.1 kB 0 B
packages/apps/esm-offline-tools-app/dist/526.js 15.7 kB 0 B
packages/apps/esm-offline-tools-app/dist/538.js 6.79 kB 0 B
packages/apps/esm-offline-tools-app/dist/541.js 383 B 0 B
packages/apps/esm-offline-tools-app/dist/56.js 3.07 kB 0 B
packages/apps/esm-offline-tools-app/dist/574.js 1.04 kB 0 B
packages/apps/esm-offline-tools-app/dist/594.js 11.4 kB 0 B
packages/apps/esm-offline-tools-app/dist/625.js 1.04 kB 0 B
packages/apps/esm-offline-tools-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-offline-tools-app/dist/696.js 410 B 0 B
packages/apps/esm-offline-tools-app/dist/733.js 290 B 0 B
packages/apps/esm-offline-tools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-offline-tools-app/dist/752.js 2.83 kB 0 B
packages/apps/esm-offline-tools-app/dist/757.js 1.21 kB 0 B
packages/apps/esm-offline-tools-app/dist/78.js 6.15 kB 0 B
packages/apps/esm-offline-tools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-offline-tools-app/dist/807.js 1.12 kB 0 B
packages/apps/esm-offline-tools-app/dist/833.js 1.23 kB 0 B
packages/apps/esm-offline-tools-app/dist/889.js 172 kB +6 B (0%)
packages/apps/esm-offline-tools-app/dist/937.js 6.61 kB 0 B
packages/apps/esm-offline-tools-app/dist/main.js 56.8 kB 0 B
packages/apps/esm-offline-tools-app/dist/openmrs-esm-offline-tools-app.js 3.31 kB 0 B
packages/apps/esm-primary-navigation-app/dist/241.js 14 kB 0 B
packages/apps/esm-primary-navigation-app/dist/263.js 6.66 kB 0 B
packages/apps/esm-primary-navigation-app/dist/319.js 200 B 0 B
packages/apps/esm-primary-navigation-app/dist/574.js 183 B 0 B
packages/apps/esm-primary-navigation-app/dist/575.js 441 B 0 B
packages/apps/esm-primary-navigation-app/dist/625.js 184 B 0 B
packages/apps/esm-primary-navigation-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-primary-navigation-app/dist/674.js 680 B 0 B
packages/apps/esm-primary-navigation-app/dist/710.js 6.44 kB 0 B
packages/apps/esm-primary-navigation-app/dist/716.js 6.12 kB 0 B
packages/apps/esm-primary-navigation-app/dist/735.js 2.64 kB 0 B
packages/apps/esm-primary-navigation-app/dist/743.js 7.25 kB 0 B
packages/apps/esm-primary-navigation-app/dist/757.js 209 B 0 B
packages/apps/esm-primary-navigation-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-primary-navigation-app/dist/807.js 235 B 0 B
packages/apps/esm-primary-navigation-app/dist/833.js 210 B 0 B
packages/apps/esm-primary-navigation-app/dist/889.js 172 kB +6 B (0%)
packages/apps/esm-primary-navigation-app/dist/948.js 3.07 kB 0 B
packages/apps/esm-primary-navigation-app/dist/953.js 12.8 kB 0 B
packages/apps/esm-primary-navigation-app/dist/main.js 4.78 kB 0 B
packages/apps/esm-primary-navigation-app/dist/openmrs-esm-primary-navigation-app.js 3.29 kB 0 B
packages/framework/esm-api/dist/openmrs-esm-api.js 9.68 kB 0 B
packages/framework/esm-breadcrumbs/dist/openmrs-esm-breadcrumbs.js 2.66 kB 0 B
packages/framework/esm-config/dist/openmrs-esm-module-config.js 7.87 kB 0 B
packages/framework/esm-dynamic-loading/dist/openmrs-esm-dynamic-loading.js 2.12 kB 0 B
packages/framework/esm-error-handling/dist/openmrs-esm-error-handling.js 894 B 0 B
packages/framework/esm-extensions/dist/openmrs-esm-extensions.js 8.05 kB 0 B
packages/framework/esm-feature-flags/dist/openmrs-esm-feature-flags.js 1.67 kB 0 B
packages/framework/esm-framework/dist/146.openmrs-esm-framework.js 6.69 kB 0 B
packages/framework/esm-framework/dist/455.openmrs-esm-framework.js 4.57 kB 0 B
packages/framework/esm-framework/dist/530.openmrs-esm-framework.js 2.92 kB 0 B
packages/framework/esm-framework/dist/645.openmrs-esm-framework.js 9.31 kB 0 B
packages/framework/esm-framework/dist/710.openmrs-esm-framework.js 6.48 kB 0 B
packages/framework/esm-framework/dist/735.openmrs-esm-framework.js 2.66 kB 0 B
packages/framework/esm-framework/dist/788.openmrs-esm-framework.js 42.9 kB 0 B
packages/framework/esm-framework/dist/openmrs-esm-framework.js 372 kB +2 B (0%)
packages/framework/esm-globals/dist/openmrs-esm-globals.js 714 B 0 B
packages/framework/esm-offline/dist/openmrs-esm-offline.js 34.4 kB 0 B
packages/framework/esm-react-utils/dist/openmrs-esm-react-utils.js 14.8 kB 0 B
packages/framework/esm-state/dist/openmrs-esm-state.js 888 B 0 B
packages/framework/esm-styleguide/dist/openmrs-esm-styleguide.js 82.7 kB 0 B
packages/framework/esm-utils/dist/openmrs-esm-utils.js 10.2 kB +3 B (0%)
packages/shell/esm-app-shell/dist/966c4dfec919951f.js 1.58 kB 0 B
packages/shell/esm-app-shell/dist/e861b352d93d75e6.js 9.88 kB 0 B
packages/shell/esm-app-shell/dist/f587be8fbac73856.js 6.04 kB 0 B
packages/shell/esm-app-shell/dist/openmrs.e66cb3888c897014.js 327 kB 0 B
packages/shell/esm-app-shell/dist/service-worker.js 57.3 kB +1 B (0%)
packages/tooling/openmrs/dist/cli.js 3.09 kB 0 B
packages/tooling/openmrs/dist/commands/assemble.js 2.73 kB 0 B
packages/tooling/openmrs/dist/commands/build.js 1.66 kB 0 B
packages/tooling/openmrs/dist/commands/debug.js 579 B 0 B
packages/tooling/openmrs/dist/commands/develop.js 1.85 kB 0 B
packages/tooling/openmrs/dist/commands/index.js 438 B 0 B
packages/tooling/openmrs/dist/commands/start.js 848 B 0 B
packages/tooling/openmrs/dist/index.js 517 B 0 B
packages/tooling/openmrs/dist/runner.js 870 B 0 B
packages/tooling/openmrs/dist/utils/config.js 726 B 0 B
packages/tooling/openmrs/dist/utils/debugger.js 529 B 0 B
packages/tooling/openmrs/dist/utils/dependencies.js 639 B 0 B
packages/tooling/openmrs/dist/utils/helpers.js 393 B 0 B
packages/tooling/openmrs/dist/utils/importmap.js 3.25 kB 0 B
packages/tooling/openmrs/dist/utils/index.js 444 B 0 B
packages/tooling/openmrs/dist/utils/logger.js 234 B 0 B
packages/tooling/openmrs/dist/utils/npmConfig.js 854 B 0 B
packages/tooling/openmrs/dist/utils/untar.js 721 B 0 B
packages/tooling/openmrs/dist/utils/variables.js 192 B 0 B
packages/tooling/openmrs/dist/utils/webpack.js 276 B 0 B
packages/tooling/webpack-config/dist/index.js 3.37 kB 0 B

compressed-size-action

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

See my comments

@@ -50,7 +50,7 @@ export function isOmrsDateStrict(omrsPayloadString: string): boolean {
}

// checking UTC offset format
if (!(omrsPayloadString[23] === "+" && omrsPayloadString[26] !== ":")) {
if (!(omrsPayloadString[23] === "+" || omrsPayloadString[23] === "-")) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like ISO considers both including and not including a : as valid (https://en.wikipedia.org/wiki/ISO_8601)

I can't remember where, but I do remember some case where we were having an issue with this... ie like an old version of Java only excepted one of the two?

Do note @ibacher that it looks like the initial code was testing that a colon was not present, so it was enforcing the "0400" format. I'm fine with removing it.... though see my comment above.

Also will flag @brandones @FlorianRappl in case they have any insight.

@@ -22,6 +22,7 @@ describe("Openmrs Dates", () => {
it("checks if a string is openmrs date", () => {
expect(isOmrsDateStrict("2018-03-19T00:00:00.000+0300")).toEqual(true);
expect(isOmrsDateStrict(" 2018-03-19T00:00:00.000+0300 ")).toEqual(true);
expect(isOmrsDateStrict("2023-10-06T12:56:56.065-0400")).toEqual(true);
// the exclusion test cases are important for strictness
expect(isOmrsDateStrict("2018-03-19 00:00:00.000+0300")).toEqual(false);
expect(isOmrsDateStrict("2018-03-19T00:00:00.000+03:00")).toEqual(false);
Copy link
Member

Choose a reason for hiding this comment

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

won't this fail test case fail without a colon check, or is there something else wrong with this that I'm missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mogoodrich , not sure I follow? This is basically already testing that having the colon is invalid. So according to the tests at least, having +03:00 is not valid, only +0300 is valid

Copy link
Member

Choose a reason for hiding this comment

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

Right... so I guess I'm confused, but I was assuming that if you removed the omrsPayloadString[26] !== ":" the isOmrsDateStrict would return "true" for this (and therefore the test woud fail).

@mseaton mseaton merged commit dde85c6 into main Oct 10, 2023
7 checks passed
@mseaton mseaton deleted the O3-2476 branch October 10, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants