Comments (8)
Please provide some code that you think is cumbersome to write without DateTimeComponents
but is easy with it. Maybe we'll figure out a better way.
from kotlinx-datetime.
Basically, the example I had was building an instant from a date manually parsed by regex.
I've now found, that there is a constructor of LocalDate from components, which I missed and it mostly cover the problem. So probably, probably, the main usecase I have in mind is unfing code between formatting and different kotlinx.datetime
class construction from some external format, where the only thing you need is an extention function filling DateTimeComponents.
But that doesn't sound so important.
from kotlinx-datetime.
unfing code between formatting and different kotlinx.datetime class construction from some external format, where the only thing you need is an extention function filling DateTimeComponents
So, the feature request is actually for something like this?
LocalDate.fromComponents { // receiver is LocalDateComponents
year = someYear
month = someMonth
dayOfMonth = someDayOfMonth
}
This would be more in line with working with DateTimeComponents
, but what are the benefits compared to just using the constructor? For DateTimeComponents
, not having a constructor is a necessity, because the set of fields may increase in the future and the fields are optional, which is not the case for something like LocalDate
. Having the compiler ensure that you provided all the necessary fields seems good.
a date manually parsed by regex
By the way, having to use regexes to parse dates is also probably a bug/missing feature in our library, so if it's us who made you go to regexes, please file another issue request.
from kotlinx-datetime.
It's not much useful for LocalDate, because it is basically subset of components.
While
Instant.fromComponents {
year = someYear
month = someMonth
dayOfMonth = someDayOfMonth
...
}
makes more sense, as otherwise you would need exponential number of constructor in Instant (e.g. TimeZone vs UtcOffset, month vs monthNumber, year+month+dayOfMonth vs LocalDate).
from kotlinx-datetime.
LocalDateTime(someYear, someMonth, someDayOfMonth, someHour, someMinute).toInstant(TimeZone.of("Europe/Berlin"))
LocalDate(someYear, someMonth, someDayOfMonth).atTime(time).toInstant(UtcOffset.ZERO)
etc.
from kotlinx-datetime.
If there's still some interest in this, please let us know, and we'll reopen the issue.
from kotlinx-datetime.
Well, I argree that the options you suggested above already provides ability of doing what I have described. Although I still think mine are more convenient. But as it is pretty easy to implement it yourself, avoiding API duplication is fine.
from kotlinx-datetime.
It's not the API duplication that's the problem but making DateTimeComponents
anything more than a thing for parsing and formatting. See, it's an unpleasant thing in general: it's mutable, non-thread-safe, people may be tempted to do invalid datetime arithmetic using its fields, etc. We'd rather not give DateTimeComponents
any more power than it already has.
from kotlinx-datetime.
Related Issues (20)
- Inconsistent behavior for dates on the edges of time overlaps
- The parsing API accepts non-ASCII digits
- Support WasmWasi HOT 1
- Is KMM still possible for apps that supports SDK 21? HOT 3
- Inherit the specified TimeZone when converting between Instant and LocalDateTime using toInstant and toLocalDateTime?
- How to get epoch milliseconds of start of the day in UTC? HOT 2
- What is the purpose of specifying TimeZone? HOT 2
- Add a dayOfYear option HOT 3
- The same serial descriptor name is used for several serializers
- Crash - Fatal Exception: java.lang.NoClassDefFoundError HOT 1
- Decide what to do with deprecated time zones
- Precision loss for NSDate HOT 5
- Easier ways to analyze a `DateTimePeriod` instance HOT 3
- Plus an minus methods on `LocalTime` and `LocalDateTime` types HOT 2
- Support obtaining the system timezone on old Debian-based distributions HOT 1
- Make admissible ranges the same on all platforms
- How can I parse the timestamp like "yyyyMMddHHmmss[ Z]" (Z is optional) with ktx-datetime? HOT 1
- fun LocalDate.atEndOfDayIn(timeZone: TimeZone): Instant HOT 4
- Consider a new name for `TimeZone.of` HOT 1
- `Instant` support Chrono fields HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlinx-datetime.