Comments (3)
Fair. We should either provide a better way to do it or at least make this code behave optimally (which is doable).
Some arguments against adding OPTIONAL_ZERO
:
- If you have several fields, the verbosity is amortized and not as bad:
alternativeParsing({
year(Padding.NONE); char('-'); monthNumber(Padding.NONE); char('-'); dayOfMonth(Padding.NONE)
}) {
year(); char('-'); monthNumber(); char('-'); dayOfMonth()
}
- When we researched how people use datetime formatting, most of the formats we looked at were used for either parsing or formatting, but not both. For people only using formats for formatting,
Padding.OPTIONAL_ZERO
is equivalent toPadding.ZERO
, and for people only using parsing, it's equivalent toPadding.NONE
. So, both classes of people get one more meaningless choice in the API. For formats that are used for both parsing and formatting, it may still help to clearly indicate the format that will be used for formatting, without having to sift through parsing-specific behavior, andalternativeParsing
does that.
Let's collect more feedback and see how widespread the problem is. Everyone, please don't hesitate to share the ugly code that you're forced to write. Maybe we'll help you improve it, or maybe we'll see that OPTIONAL_ZERO
is an absolute necessity.
from kotlinx-datetime.
Will it parse something like 2024-3-07
? I'm not sure if Padding.NONE allows having padding.
But I agree, that reusing for both formatting and parsing is not a common case.
from kotlinx-datetime.
Will it parse something like 2024-3-07?
Yes.
I'm not sure if Padding.NONE allows having padding.
It does. We'll include this in the documentation, this information is missing.
from kotlinx-datetime.
Related Issues (20)
- Consider deprecating `DateTimePeriod.plus` and `DatePeriod.plus` HOT 4
- Consider moving `Instant` and `Clock` to the standard library
- Not supported on Android 7.0? What are the minimum supported Android and IOS versions? HOT 2
- Missing methods we had before in Java HOT 3
- Unable to execute kotlin native packaging HOT 5
- Localization format HOT 1
- `LocalDateTime` to `Instant` conversion incorrect for mingwX64 target after daylight savings in `America/New_York` on 0.6.0 HOT 11
- Add a top-level description to the API reference
- Issue with R8 minification HOT 3
- 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
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.