Comments (12)
plus(1.days)
is incorrect, it ignores DST transitions. Please use plus(1, DateTimeUnit.DAY, zone)
instead.
A more robust approach that takes DST transitions near midnight into account:
val tomorrowStart = currentInstant.toLocalDate(zone).date.plus(1, DateTimeUnit.DAY).atStartOfDayIn(zone) - 1.seconds
val tomorrowEnd = currentInstant.toLocalDate(zone).date.plus(2, DateTimeUnit.DAY).atStartOfDayIn(zone) - 1.minutes
from kotlinx-datetime.
Instant.atDate
would also be good
from kotlinx-datetime.
Not in this form, but if you explain your use case, we could potentially add something other than this to help you.
from kotlinx-datetime.
I use the copy extension multiple times, I just thought it would be good to have it
Also atTime
and atDate
are helpful if you are looking for a quick way to modify Instant with date and time
I just think they'd be helpful
from kotlinx-datetime.
Examples of use cases:
- Finding the last time it was Monday to understand if two days are on the same week,
- Setting the seconds and nanoseconds to zero for printing,
- Finding the same date/time in a different year.
Essentially, the question is, why do you think they'd be helpful?
from kotlinx-datetime.
Everytime I need to only change the day
in a LocalDateTime
object I must create it completely, meaning I will call the constructor with all parameters specified, This is a lot verbose, just for changing the day
val time : LocalDateTime = ~
val newTime = time.copy(dayOfMonth = 8)
VS
val time : LocalDateTime = ~
val newTime = LocalDateTime(
year = year,
monthNumber = monthNumber,
dayOfMonth = 8,
hour = hour,
minute = minute,
second = second,
nanosecond = nanosecond
)
from kotlinx-datetime.
Why do you need to change the day?
from kotlinx-datetime.
because user said he wants, but the question is why does he want to do it ? 😂
from kotlinx-datetime.
So, your user asked you: "I like everything, but please, replace these dates with those where the day of the month is 8, 16, and 23 because I simply like these numbers. You don't need to know anything else." Is this what happened?
from kotlinx-datetime.
Okay, I was being sarcastic, User asked me to add a reminder, After two days, I added two days to current instant (this is the current date when user created it), User can also select weeks, months, having these extensions made it easier, thought I'd just post it here
from kotlinx-datetime.
To add two days, you can do date.plus(2, DateTimeUnit.DAY)
, there's no need to implement addition manually.
As for "selecting weeks," I still don't understand what you mean.
from kotlinx-datetime.
Do you think I could replace this code with something from the library ?
val tomorrowStart = currentInstant.atTime(23, 59, 59, 0)
val tomorrowEnd = currentInstant.plus(1.days).atTime(23, 59, 0, 0)
from kotlinx-datetime.
Related Issues (20)
- API reference improvements HOT 1
- Consider adding parsing and formatting support for `kotlin.time.Duration`
- Provide custom formats for `DateTimePeriod`
- Introduce serializers corresponding to custom formats HOT 3
- Fix the ISO serializers omitting seconds when zero and emitting fractional parts in groups of three signs HOT 4
- Locale-aware formatting (but not parsing)
- Publish the design documents for datetime formats
- Update Kotlin version HOT 3
- ABI incompatible change on `kotlinx.datetime/LocalDateTime.Companion.parse` function in 0.6.0 release HOT 2
- Failed requirement on strange time zone HOT 1
- Potential improvements and input preservation in parsing and formatting error messages HOT 1
- Feature: building instant from DateTimeComponents HOT 8
- Feature: optional padding HOT 3
- InstantRange HOT 1
- Instant.parse(..) inconsistent between jvm and ios targets HOT 2
- Consider removing `Clock.asTimeSource` HOT 10
- [iOS] Fix parsing string without seconds HOT 1
- allTests Gradle task fails after adding v0.6.0-RC.2 dependency HOT 3
- Consider deprecating `DateTimePeriod.plus` and `DatePeriod.plus` HOT 4
- Consider moving `Instant` and `Clock` to the standard library
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.