tiffany352 / rink-rs

Unit conversion tool and library written in rust
https://rinkcalc.app/about
GNU General Public License v3.0
442 stars 28 forks source link

Make dates with numerical offsets get parsed correctly #51

Closed DeeUnderscore closed 4 years ago

DeeUnderscore commented 4 years ago

Currently, if you specify a date like #2020-01-01 05:00:00 +05:00#, instead of getting 5am in the UTC+5 timezone, you will get UTC 5am converted to the UTC+5 timezone (ie, 10am). You can test this by comparing dates that are the same and should return a time difference of 0:

> #2020-01-01 05:00:00 +05:00# - #2020-01-01 00:00:00 +00:00#
5 hour, 0 second (time)

This PR makes dates specified with offsets get parsed as local time at that offset, which is the probably what's expected. There is some code duplication here that could perhaps be avoided with wider refactoring, but it achieves the correct behavior.

codecov[bot] commented 4 years ago

Codecov Report

Merging #51 into master will decrease coverage by 0.04%. The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
- Coverage   82.88%   82.83%   -0.05%     
==========================================
  Files          20       20              
  Lines        4854     4858       +4     
==========================================
+ Hits         4023     4024       +1     
- Misses        831      834       +3
Impacted Files Coverage Δ
tests/query.rs 98.29% <100%> (+0.02%) :arrow_up:
src/date.rs 95.8% <50%> (-0.41%) :arrow_down:
src/substance.rs 47.2% <0%> (-0.27%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d37bedc...6039107. Read the comment docs.

tiffany352 commented 4 years ago

Thanks!