DEV Community

Discussion on: How a calculation of previous month in golang can break production

 
pochmurnygrzech profile image
Grzegorz Kotlarz • Edited

Very thanks for your input and curiosity. I also dig deeper into other languages. Ruby and Java behave like C#.

Interesting thing happens in Rust, where you don't have a method to add or subtract months. You can however do something like this:

    let end_of_april = NaiveDate::from_ymd(end_of_may.year(), end_of_may.month() - 1, end_of_may.day());
Enter fullscreen mode Exit fullscreen mode

and it... panics because of the out-of-range date. You can check the snippet

I ran onto it here.

Thread Thread
 
glavic profile image
Glavić

This is really interesting, that one language decided to overflow in positive and other into negative days... So when developing we must be familiar with this and act accordingly. Tnx for the overview in other languages.