Exciting Update: Dart 2.19.0 Introduces dateTime.copyWith Method
Written on
Chapter 1: Introduction to Dart 2.19.0
On October 20, 2022, a new version of the Dart programming language was released, introducing numerous breaking changes and enhancements. In this article, I'll focus on one particular feature that piqued my interest. For a detailed overview of the other changes, please refer to the link provided at the end of this piece.
Copying DateTime with Modifications
Often, developers find themselves needing to duplicate a DateTime object while altering one or more of its components. For instance, when displaying a graph that shows sensor strength over time, users may wish to select a specific month, year, or day. To determine the startDate, you would typically retrieve the current DateTime and then subtract from the month, year, or day as needed.
In such scenarios, having the ability to replicate a date and modify a single aspect—like changing today’s date to yesterday or to a specific date—becomes extremely beneficial. Patrick Cornelißen proposed the inclusion of a fundamental method to manage this requirement, as he frequently relied on his own utility function.
The proposal was deliberated upon, and Lasse Nielsen brought this concept to fruition, meaning that starting from version 2.19.0, Dart now features the dateTime.copyWith method. Here’s a brief overview of its functionality:
The introduction of this feature excites me as it demonstrates that even the DateTime class can be augmented with more practical functionalities. Moreover, it highlights the collaborative and innovative spirit of the Dart community, showing that Dart is challenging the conventional norms!
I appreciate the efforts put into this improvement!
Encouragement to Engage
The more readers engage with my articles, the more time I can dedicate to creating them. If you enjoyed this content and would like to see more topics related to Dart, please consider subscribing via email, clapping, liking, and sharing. Thank you for your support!
Source Links
- Official Dart Page
- Dart GitHub Repository
Stay Updated on Software Engineering
Join over 1,500 subscribers to Tom Smykowski’s articles for just $5 a month! Gain access to all of Tom's work on Medium and help inspire more captivating stories. Become a member today!