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

Issue #660 whitespace exact #807

Merged
merged 4 commits into from Mar 18, 2023

Conversation

jtmoon79
Copy link
Contributor

@jtmoon79 jtmoon79 commented Aug 31, 2022

be exact about whitespace Issue #660

Be exact about whitespace in parsing. This changes
pattern matching in format::parse::parse as it does not allow
arbitrary whitespace before, after, or between the datetime specifiers.

format/parse.rs:datetime_from_str is exact about whitespace in
the passed data s and passed strftime format fmt.

Also be more exacting about colons and whitespace around timezones.
Instead of unlimited colons and whitespace, only match a more limited
possible set of leading colons and whitespace.
(See fn colon_or_space https://github.com/chronotope/chrono/pull/807/files#diff-679cb1eea69fd36c51536ec228e61d6b0e40ade95997877f6f853e6ad31de5f1R224-R227).

Also rename some test functions to better describe what is tested.


To help reviewers understand how test results changed before and after, I created a branch Issue660_whitespace_exact_try6_prechange_testsonly that has added same set of test cases as this branch Issue660_whitespace_exact_try6, but does not have the underlying changes for whitespace and colons (i.e. Issue660_whitespace_exact_try6_prechange_testsonly is the "before significant changes" branch, and Issue660_whitespace_exact_try6 is the "after significant changes" branch) https://github.com/jtmoon79/chrono/compare/Issue660_whitespace_exact_try6_prechange_testsonly..Issue660_whitespace_exact_try6
The tests that result in different values are marked with // TESTDIFF.


This is a lot of changes in this PR. IMO, it covers one idea so it suitable for one PR; colons and whitespace should be handled more exactly. The changes for both of these tended to be the same code lines, so I thought it was sensible to make the changes all in one commit. Hopefully the additional test cases provide enough confidence for accepting this significant change.


Thanks for contributing to chrono!

  • Have you added yourself and the change to the changelog? (Don't worry
    about adding the PR number)
  • If this pull request fixes a bug, does it add a test that verifies that
    we can't reintroduce it?

I did not add to the CHANGELOG.md because there was no section 0.5 to add a new line item. I can add such a section if the reviewers would like.
(In a prior review, it was recommended that these changes should wait until a significant version change number (like from 0.4... to 0.5). #660 (comment) )


Also see initial change proposal explanation at #660 (comment)

This PR is a further draft of #786 .

@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch from 977a8cc to a37d1e0 Compare August 31, 2022 21:49
@jtmoon79 jtmoon79 changed the title Issue660 whitespace exact (try6) Issue660 whitespace exact Aug 31, 2022
src/datetime/tests.rs Outdated Show resolved Hide resolved
src/datetime/tests.rs Outdated Show resolved Hide resolved
src/datetime/tests.rs Show resolved Hide resolved
src/format/parse.rs Show resolved Hide resolved
@jtmoon79 jtmoon79 marked this pull request as draft September 1, 2022 00:18
@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch 3 times, most recently from 03dc4a4 to 448879d Compare September 1, 2022 07:23
@jtmoon79 jtmoon79 marked this pull request as ready for review September 1, 2022 07:44
@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch from 448879d to 7765f86 Compare September 1, 2022 08:02
src/datetime/tests.rs Show resolved Hide resolved
src/format/mod.rs Show resolved Hide resolved
src/format/mod.rs Outdated Show resolved Hide resolved
@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch 4 times, most recently from edb7eb5 to 7ba26b5 Compare September 1, 2022 22:49
@jtmoon79
Copy link
Contributor Author

jtmoon79 commented Sep 2, 2022

@djc @esheppa any opinion on this PR?

@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch 3 times, most recently from cb4e2ac to a736e1e Compare September 2, 2022 06:08
@djc
Copy link
Contributor

djc commented Sep 2, 2022

@jtmoon79 both @esheppa and I are working on maintaining this project as volunteers, so when you start pinging us after 1 day it feels entitled. We will review this when we have time, usually that doesn't take more than a few days.

@jtmoon79
Copy link
Contributor Author

jtmoon79 commented Sep 2, 2022

@jtmoon79 both @esheppa and I are working on maintaining this project as volunteers, so when you start pinging us after 1 day it feels entitled. We will review this when we have time, usually that doesn't take more than a few days.

Pardon me. Yes, per your convenience.

@djc
Copy link
Contributor

djc commented Sep 5, 2022

Okay, this is way too big to review in one go. It can be all in one PR but then I'd like the big commit split up in more, smaller commits. Multiple PRs would also be a fine approach. Here's what I'm thinking:

  • One commit to add test cases that verify the current behavior (that will still pass after your changes)
  • One commit to make the actual code changes and relevant document changes, and changes any tests as needed
  • One commit to add further tests that verify the new behavior

Some further notes: please remove type annotations unless necessary for the compiler, don't use variable names like s_c (although c is fine if it is for a char) -- it seemed like you were using _c as a sort of Hungarian notation? Also for tests that test invalid input, please add a comment saying why the particular line of input is invalid.

@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch from 853d943 to 742fb95 Compare September 10, 2022 08:11
@jtmoon79
Copy link
Contributor Author

jtmoon79 commented Sep 10, 2022

Okay, this is way too big to review in one go. It can be all in one PR but then I'd like the big commit split up in more, smaller commits.

This PR push is slightly different than your ask. It's currently 2 commits. I can revise into 3 commits if needed. Hopefully my forthcoming rationale is agreeable. 🙂

I'd like the big commit split up in more, smaller commits.

I made two large commits for easier comparison:

  • first commit that adds many test cases and no behavior changes aaf4c0a
  • second commit that adds behavior changes, tweaks test cases, adds few test cases 72d1d83

Having this in two commits makes "before/after behavior comparison" easier for humans to grok, IMO.


I dropped PR creep around function name changes and a few other things.


One commit to add test cases that verify the current behavior (that will still pass after your changes)

Commit aaf4c0a

This adds a substantial number of tests. Some may seem redundant. But they are to help clarify behavior changes that will occur in the next commit.

Since there were significant changes to parse_internal in the next commit, I also added tests for other Items like, for example, Nanosecond3NoDot. e.g. for testing of Nanosecond3NoDot make sure test number lengths of 2 and 4 ("edges") and 6, 9 (other signifcant fraction lengths).
These seemingly unrelated test cases gave me a little more confidence that upcoming changes did not affect adjacent parsing.


One commit to make the actual code changes and relevant document changes, and changes any tests as needed

Commit 72d1d83

This introduces major parsing changes.

One notable change: I reduced timezone colon delimiters from arbitrary unlimited whitespace+colon to one or zero of
patterns ":", " ", " :", ": ", or " : "., e.g. "0430", "04:30", "04 30", "04 :30", "04: 30", or "04 : 30"
This seemed like a reasonable compromise of previous matching flexibility and desired matching exactness.

Some tests that appear added or removed might be just moved,
e.g. the test case " 4 : 3 : 2.1 " here:

--- a/src/naive/time/tests.rs
+++ b/src/naive/time/tests.rs
@@ -196,9 +196,6 @@ fn test_date_from_str() {
         "0:0:0",
         "0:0:0.0000000",
         "0:0:0.0000003",
-        " 4 : 3 : 2.1 ",
-        " 09:08:07 ",
-        " 9:8:07 ",
         "01:02:03",
         "4:3:2.1",
         "9:8:7",
@@ -266,6 +263,18 @@ fn test_date_from_str() {
         "1441497364.649",    // valid datetime, not a NaiveTime
         "+1441497364.649",   // valid datetime, not a NaiveTime
         "+1441497364",       // valid datetime, not a NaiveTime
+        "01 :02:03",         // space after hour
+        "01: 02:03",         // space before minute
+        "01 : 02:03",        // space around hour-minute divider
+        "01:02 :03",         // space after minute
+        "01:02: 03",         // space before second
+        "01:02 : 03",        // space around minute-second divider
+        "01:02:03 .456",     // space after second
+        "01:02:03. 456",     // space before fraction
+        "01:02:03 ",         // trailing space
+        "01:02:03.456 ",     // trailing space
+        " 01:02:03",         // leading space
+        " 4 : 3 : 2.1 ",     // spaces intermixed throughout

One commit to add further tests that verify the new behavior

I thought this to be unnecessary for my "A/B comparison" approach.


please remove type annotations unless necessary for the compiler

Removed.


don't use variable names like s_c (although c is fine if it is for a char) -- it seemed like you were using _c as a sort of Hungarian notation?\

Renamed unused variable _c to _.

There are some places using c_ (a char). The c_ is to help humans distinguish from outer scope variable c (a char).


Also for tests that test invalid input, please add a comment saying why the particular line of input is invalid.

I added comment explanations for many invalid input tests. However, I did not add a comment for all invalid input tests.
I was concerned that in some areas those comments would decrease grokability.
Happy to add more comments to the test cases if requested.


I ran cargo fmt at the project top-level directory.
This produced some unexpected alignments of trailing comments, e.g.

+        "2012 -12-12T12:12:12Z",                                     // space after year
+        "2012  -12-12T12:12:12Z",                                    // multi space after year
+        "2012- 12-12T12:12:12Z",                                     // space after year divider
+        "2012-  12-12T12:12:12Z", // multi space after year divider
+        "2012-12-12T 12:12:12Z",  // space after date-time divider

At first glance, this looks like a bug in rustfmt.

@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch 4 times, most recently from 26749fb to c671464 Compare September 10, 2022 09:29
Add tests for timezone parsing infinite whitespace and colons.

Prepatory tests for next commit around constraining timezone and
colons.
Constrain timezone middle-colon separator string from
infinite intermixed whitespace and colons
to possible patterns `":"`, `" "`, `" :"`, `": "`, or `" : "`.
A reasonable trade-off of previous extreme flexibility for
a little flexbility and concise input.

Issue chronotope#660
@jtmoon79 jtmoon79 force-pushed the Issue660_whitespace_exact_try6 branch from f23034b to 98854dc Compare March 17, 2023 21:27
@jtmoon79
Copy link
Contributor Author

Would it be feasible to squash the current commit history down

Squashed.

Your help with maintaining this project would be much appreciated!

I'll subscribe to the github alerts. I'll comment on PRs where I can.

@djc djc merged commit 2fcdd9e into chronotope:main Mar 18, 2023
32 checks passed
@jtmoon79 jtmoon79 mentioned this pull request Apr 5, 2023
pitdicker added a commit to pitdicker/chrono that referenced this pull request May 30, 2023
djc pushed a commit that referenced this pull request May 30, 2023
pitdicker added a commit to pitdicker/chrono that referenced this pull request Jun 3, 2023
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jun 12, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [chrono](https://github.com/chronotope/chrono) | dependencies | patch | `0.4.24` -> `0.4.26` |

---

### Release Notes

<details>
<summary>chronotope/chrono</summary>

### [`v0.4.26`](https://github.com/chronotope/chrono/releases/tag/v0.4.26): 0.4.26

[Compare Source](chronotope/chrono@v0.4.25...v0.4.26)

The changes from [#&#8203;807](chronotope/chrono#807) we merged for 0.4.25 unfortunately restricted parsing in a way that was incompatible with earlier 0.4.x releases. We reverted this in [#&#8203;1113](chronotope/chrono#1113). A small amount of other changes were merged since.

-   Update README ([#&#8203;1111](chronotope/chrono#1111), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Revert backport of [#&#8203;807](chronotope/chrono#807) ([#&#8203;1113](chronotope/chrono#1113), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Update to 2021 edition ([#&#8203;1109](chronotope/chrono#1109), thanks to [@&#8203;tottoto](https://github.com/tottoto))
-   Fix `DurationRound` panics from issue [#&#8203;1010](chronotope/chrono#1010) ([#&#8203;1093](chronotope/chrono#1093), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   tests: date path consolidate (branch 0.4.x) ([#&#8203;1090](chronotope/chrono#1090), thanks to [@&#8203;jtmoon79](https://github.com/jtmoon79))
-   Parse tests nanosecond bare dot (branch 0.4.x) ([#&#8203;1098](chronotope/chrono#1098), thanks to [@&#8203;jtmoon79](https://github.com/jtmoon79))
-   yamllint cleanup lint.yml test.yml ([#&#8203;1102](chronotope/chrono#1102), thanks to [@&#8203;jtmoon79](https://github.com/jtmoon79))
-   Remove num-iter dependency ([#&#8203;1107](chronotope/chrono#1107), thanks to [@&#8203;tottoto](https://github.com/tottoto))

Thanks on behalf of the chrono team ([@&#8203;djc](https://github.com/djc) and [@&#8203;esheppa](https://github.com/esheppa)) to all contributors!

### [`v0.4.25`](https://github.com/chronotope/chrono/releases/tag/v0.4.25): 0.4.25

[Compare Source](chronotope/chrono@v0.4.24...v0.4.25)

Time for another maintenance release. This release bumps the MSRV to 1.56; given MSRV bumps in chrono's dependencies (notably for syn 2), we felt that it no longer made sense to support any older versions. Feedback welcome in our issue tracker!

##### Additions

-   Bump the MSRV to 1.56 ([#&#8203;1053](chronotope/chrono#1053))
-   Apply comments from MSRV bump ([#&#8203;1026](chronotope/chrono#1026), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Remove num-integer dependency ([#&#8203;1037](chronotope/chrono#1037), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Add `NaiveDateTime::and_utc()` method ([#&#8203;952](chronotope/chrono#952), thanks to [@&#8203;klnusbaum](https://github.com/klnusbaum))
-   derive `Hash` for most pub types that also derive `PartialEq` ([#&#8203;938](chronotope/chrono#938), thanks to [@&#8203;bruceg](https://github.com/bruceg))
-   Add `parse_and_remainder()` methods ([#&#8203;1011](chronotope/chrono#1011), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Add `DateTime::fix_offset()` ([#&#8203;1030](chronotope/chrono#1030), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Add `#[track_caller]` to `LocalResult::unwrap` ([#&#8203;1046](chronotope/chrono#1046), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Add `#[must_use]` to some methods ([#&#8203;1007](chronotope/chrono#1007), thanks to [@&#8203;aceArt-GmbH](https://github.com/aceArt-GmbH))
-   Implement `PartialOrd` for `Month` ([#&#8203;999](chronotope/chrono#999), thanks to [@&#8203;Munksgaard](https://github.com/Munksgaard))
-   Add `impl From<NaiveDateTime> for NaiveDate` ([#&#8203;1012](chronotope/chrono#1012), thanks to [@&#8203;pezcore](https://github.com/pezcore))
-   Extract timezone info from tzdata file on Android ([#&#8203;978](chronotope/chrono#978), thanks to [@&#8203;RumovZ](https://github.com/RumovZ))

##### Fixes

-   Prevent string slicing inside char boundaries ([#&#8203;1024](chronotope/chrono#1024), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   fix IsoWeek so that its flags are always correct ([#&#8203;991](chronotope/chrono#991), thanks to [@&#8203;moshevds](https://github.com/moshevds))
-   Fix out-of-range panic in `NaiveWeek::last_day` ([#&#8203;1070](chronotope/chrono#1070), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Use correct offset in conversion from `Local` to `FixedOffset` ([#&#8203;1041](chronotope/chrono#1041), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Fix military timezones in RFC 2822 parsing ([#&#8203;1013](chronotope/chrono#1013), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Guard against overflow in NaiveDate::with_\*0 methods ([#&#8203;1023](chronotope/chrono#1023), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Fix panic in from_num_days_from_ce_opt ([#&#8203;1052](chronotope/chrono#1052), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))

##### Refactoring

-   Rely on std for getting local time offset ([#&#8203;1072](chronotope/chrono#1072), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Make functions in internals const ([#&#8203;1043](chronotope/chrono#1043), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Refactor windows module in `Local` ([#&#8203;992](chronotope/chrono#992), thanks to [@&#8203;nekevss](https://github.com/nekevss))
-   Simplify from_timestamp_millis, from_timestamp_micros ([#&#8203;1032](chronotope/chrono#1032), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Backport [#&#8203;983](chronotope/chrono#983) and [#&#8203;1000](chronotope/chrono#1000) ([#&#8203;1063](chronotope/chrono#1063), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))

##### Documentation

-   Backport documentation improvements ([#&#8203;1066](chronotope/chrono#1066), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Add documentation for %Z quirk ([#&#8203;1051](chronotope/chrono#1051), thanks to [@&#8203;campbellcole](https://github.com/campbellcole))
-   Add an example to Weekday ([#&#8203;1019](chronotope/chrono#1019), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))

##### Internal improvements

-   Gate test on `clock` feature ([#&#8203;1061](chronotope/chrono#1061), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   CI: Also run tests with `--no-default-features` ([#&#8203;1059](chronotope/chrono#1059), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Prevent `bench_year_flags_from_year` from being optimized out ([#&#8203;1034](chronotope/chrono#1034), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Fix test_leap_second during DST transition ([#&#8203;1064](chronotope/chrono#1064), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Fix warnings when running tests on Windows ([#&#8203;1038](chronotope/chrono#1038), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Fix tests on AIX ([#&#8203;1028](chronotope/chrono#1028), thanks to [@&#8203;ecnelises](https://github.com/ecnelises))
-   Fix doctest warnings, remove mention of deprecated methods from main doc ([#&#8203;1081](chronotope/chrono#1081), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Reformat `test_datetime_parse_from_str` ([#&#8203;1078](chronotope/chrono#1078), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   GitHub yml shell `set -eux`, use bash ([#&#8203;1103](chronotope/chrono#1103), thanks to [@&#8203;jtmoon79](https://github.com/jtmoon79))
-   test: explicitly set `LANG` to `c` in gnu `date` ([#&#8203;1089](chronotope/chrono#1089), thanks to [@&#8203;scarf005](https://github.com/scarf005))
-   Switch test to `TryFrom` ([#&#8203;1086](chronotope/chrono#1086), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   Add test for issue 551 ([#&#8203;1020](chronotope/chrono#1020), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   RFC 2822 single-letter obsolete tests ([#&#8203;1014](chronotope/chrono#1014), thanks to [@&#8203;jtmoon79](https://github.com/jtmoon79))
-   \[CI] Lint Windows target and documentation links ([#&#8203;1062](chronotope/chrono#1062), thanks to [@&#8203;pitdicker](https://github.com/pitdicker))
-   add test_issue\_866 ([#&#8203;1077](chronotope/chrono#1077), thanks to [@&#8203;jtmoon79](https://github.com/jtmoon79))
-   Remove AUTHORS metadata ([#&#8203;1074](chronotope/chrono#1074))

On behalf of [@&#8203;djc](https://github.com/djc) and [@&#8203;esheppa](https://github.com/esheppa), thanks to all contributors!

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDUuMSIsInVwZGF0ZWRJblZlciI6IjM1LjExNS4yIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1909
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
This was referenced Jul 5, 2023
pitdicker added a commit to pitdicker/chrono that referenced this pull request Feb 12, 2024
pitdicker added a commit to pitdicker/chrono that referenced this pull request Feb 16, 2024
pitdicker added a commit to pitdicker/chrono that referenced this pull request Feb 16, 2024
pitdicker added a commit to pitdicker/chrono that referenced this pull request Feb 16, 2024
pitdicker added a commit to pitdicker/chrono that referenced this pull request Feb 16, 2024
pitdicker added a commit to pitdicker/chrono that referenced this pull request Feb 16, 2024
pitdicker added a commit to pitdicker/chrono that referenced this pull request Feb 19, 2024
pitdicker added a commit that referenced this pull request Feb 20, 2024
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.

None yet

3 participants