-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create the dart:time
API for processing dates with functional programming
#56023
Comments
Labels: |
Could you explain how this functionality is not provided by existing mechanisms? void main() {
DateTime initialDate = DateTime.of(2024, 06, 12);
DateTime finalDate = initialDate.plus(Period.ofDays(5));
int thirty = Duration.between(initialTime, finalTime).getSeconds();
} can already be written today, in dart, with: DateTime initialDate = DateTime.of(2024, 06, 12);
DateTime finalDate = initialDate.add(Duration(days: 5));
int thirty = initialDate.difference(finalDate).inSeconds; The DateFormat class in the first party maintained Adding a If you'd like inspiration, you can take a look at a package like I think its important to recognize that dart has solutions for many problems already, and they are generally solved much better than in Java, where a lot of code is burdened by backwards-compatibility and verbosity as a core principle of the language. |
@clragon You are right, I have no doubt that the Dart language currently cannot solve these problems. My main objective is to support functional programming, take that into account. If we pose the problem of calculating the difference of days in two dates, we can solve it in 2 ways depending on the programming paradigm we are using. If we use traditional object-oriented programming the solution would look like this void main() {
DateTime initialDate = DateTime(2024, 06, 12);
DateTime finalDate = initialDate.add(Duration(days: 5));
int thirty = initialDate.difference(finalDate).inSeconds;
} If we use functional programming the solution would look like this void main() {
DateTime initialDate = DateTime.of(2024, 06, 12);
DateTime finalDate = initialDate.plus(Period.ofDays(5));
int thirty = Duration.between(initialTime, finalTime).getSeconds();
} This form is necessary so that the date calculations can comply with the principle of void main() {
Stream<DateTime> initialDate = Stream.value( DateTime.of(2024, 06, 12) );
Stream<DateTime> finalDate = Stream.value( DateTime.of(2024, 06, 12).plus(Period.ofDays(5)) );
Optional<int> opt = Stream.zip([initialDate, finalDate])
.map((tuple) => Duration.between(tuple.t1, tuple.t2).getSeconds())
.first
int thirty = opt.get();
} As you can see, the dates API is combined with the Streams, which is why I am making this proposal to achieve algorithms that work in this way. My proposal is not intended to convert Dart into Java only to assume functional programming when you talk about vervosity it is strange because functional programming is a solution for that problem Then I check the |
We are not planning to do that. Developers are free to create whatever packages they see fit though. |
Greetings, the purpose of this proposal is to propose an API to perform mathematical operations on dates, which the DateTime type cannot resolve by itself. Also providing some additional utilities for working with dates, this API takes inspiration from the java.time API which is optimized to work with functional programming
We must clarify that some classes will not be implementable because the
DateTime
type exists in thedart:core
package and thedart:time
api classes must avoid cyclic dependency to avoid this it is necessary to implement themap()
function To avoid the problem of cyclical dependencies, an example would look like this:An implementable class would be
Duration
which would look like thisAn implementable class would be
Period
which would look like thisAnother important implementation is
DateFormat
to represent a date in StringAnother important implementation is
DateConvert
to convert dates into other forms of time e.g.As you can see the possibilities will be very positive for the developer community, some java.time examples to inspire you
I was investigating if there is a library for this and I only found dart_date but it does not comply with the form of functional programming
The text was updated successfully, but these errors were encountered: