On 20/10/22 a new version of Dart programming was released. It includes a lot of breaking changes and fixes. Today I will only describe one new feature that caught my attention. You can review the rest of changes by the link at the end of article.
Copying DateTime With Changes
Often, you need to copy DateTime while changing one or more elements.
For example when you show a graph displaying a range of sensor strength. User can choose a month, year or day. To calculate the startDate, you get the current DateTime, and then minus one from month, year or day.
In that case or others, it is useful to copy a date, and than change only one element like day, from today to yesterday, or to given date.
Patrick Cornelißen proposed including a core method handling that use case, because he often relies on his own helper method.
The proposal was discussed, and Lasse Nielsen implemented the feature meaning that since version 2.19.0 Dart comes with dateTime.copyWith method. Here’s a glimpse of how it works:
I love this change because it proves even DateTime class can be extended with more useful features. It also shows how friendly and open minded Dart community is. Dart is breaking the status quo!
The more people read my articles, the more time I can spend for writing them. So, if you like it, and would like me to cover more Dart topics please subscribe via email, clap, like and share. Cheers!
Official Dart Page
Would you like to be up-to-date with software engineering? Already over 1,500 people subscribe to Tom Smykowski’s articles. Now you can join them too. For just $5 a month, you will get access to not only his but also ALL ARTICLES on Medium and let Tom Smykowski write more interesting stories! Become a member now!