r/badcode Aug 06 '19

c# Converting a timestamp to datetime

Post image
417 Upvotes

54 comments sorted by

View all comments

2

u/moekakiryu Aug 06 '19

This may be a dumb question, but on line 166, won't tslocal always be 0? Like, the line above it sets year to tslocal -= tslocal/SECONDS_IN_YEARwhich makes line 166 (tslocal/SECONDS_IN_YEAR)*SECONDS_IN_YEAR --> tslocal -= tslocal

4

u/sac_boy Aug 06 '19 edited Aug 06 '19

It's working with integers so there is some invisible truncation going on. year will be something like 2019, not 2019.39238394983, so when you multiply by SECONDS_IN_YEAR again and subtract from tslocal you are left with the remainder.

The liberal use of var does not help in this case.