Refactor time parsing with thread-safe localtime and leap year fix#4692
Conversation
4af095c to
c391f85
Compare
|
@kbevers I see the original formula to translate to decimal year comes from 0b5c362 . I remember that ISO 19111 doesn't mention anything about that (or maybe that leap years don't matter). Anyway in src/conversions/unitconvert.cpp, we do take into leap years. Should we align hgridshift and vgridship on that ? |
src/transformations/hgridshift.cpp
Outdated
There was a problem hiding this comment.
Maybe the refactoring can be done now
It's been a while so I don't remember my thought process but I guess I didn't see any reason to complicate things. Usually we are looking a rates of mm or cm pr year in a deformation model. The difference between 1/365 and 1/366 of a year is neglicable and well within the uncertainty of any imperical model. But accounting for leap years is more correct and with a bit of refactoring everything will be a little bit nicer for the next person. |
|
I have refactored the duplicated |
34e6486 to
903cbdb
Compare
|
The refactored time function looks good. I'd like to see a more descriptive commit message for the clang-format fix, as it's not clear to me what is actually being fixed. |
|
i think it would be better if i will squash all the 3 commits into one in order to not create any chaos and give a proper description |
903cbdb to
1408e44
Compare
That's an option, yes. It still doesn't explain what's going on with the changes to satisfy clang-format. If I look at this commit in ten years I'd like to know why changes regarding opening of grid files is mixed with refactoring of functionality to parse time. Ideally this PR is rebased into two commits: one with the changes to time parsing and the other that fixes whatever clang-format complains about. |
|
@kbevers so you would recommend me splitting it into two commits one stating about the clang fixtures (due to CI failures i faced) and the other one abt refactoring ? |
|
Yes |
Extract duplicated t_final parameter parsing logic from hgridshift.cpp and vgridshift.cpp into pj_parse_t_final() function in param.cpp. Changes: - Add pj_parse_t_final() to param.cpp with thread-safe time handling - Replace localtime() with localtime_r()/localtime_s() for thread safety - Fix leap year calculation (proper 365/366 day handling) - Support both numeric t_final values and t_final=now keyword - Remove duplicate code from transformation files - Add function declaration to proj_internal.h Resolves TODO comment present in both transformation files. Fixes thread safety issue when multiple threads use +t_final=now.
1408e44 to
645954b
Compare
|
@kbevers the clang format issue from the ci failure was specifically abt formating the new code (one i added) it would be counterproductive to create one commit with improperly formatted new code and then a second commit just to fix that formatting the refactoring should contain the properly formatted code from the start istelf |
|
@KinshukSS2 in a previous rendition of this PR you had changes in |
Those changes are about using |
Well, they were initially put in a commit that said "fix clang-format" which has since been force-pushed away. And now the changes aren't here at all. The thing I've been going on about was to get an explanation for what was going on, as it didn't look like anything to do with the stated purpose of the PR. But that discussion is futile now that those lines of code are gone from the PR. This is ready to merge once the tests have run successfully. |
replace non-thread-safe
localtime()withlocaltime_r()(POSIX) /localtime_s()(Windows) in hgridshift and vgridshift+t_final=nowhandling.also fix leap year calculation: use 366 days for leap years instead of hardcoded 365.
Closes #4691