https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlinx-datetime
  • m

    Marc Knaup

    08/18/2020, 10:05 PM
    Can't
    Instant
    be named
    Timestamp
    ? The former is so... scientific. Not easy to grasp, esp. for a general purpose programming language.
    s
    e
    • 3
    • 4
  • b

    Brutus5000

    08/19/2020, 9:26 AM
    Hi guys! I just joined here after your announcement on the topic. I am working a lot with the JVM time package and miss a lot of stuff in kotlinx-datetime. How and where would you like to get feature requests? Here? Github? The forum discussion?
    b
    i
    • 3
    • 2
  • v

    Vitali Plagov

    09/09/2020, 6:55 PM
    Hello. I'm trying to use
    datetime
    library for the following scenario. Can you please help me with it? I need an object with date of now with time at 10:00. Next, I need to change this object by adding one day or by subtracting one day (depending on a certain condition). So, I made the first part:
    var todayAtTen = Clock.System.todayAt(TimeZone.UTC).atTime(hour = 10, minute = 0)
    but can't make a second. How can I modify this object by adding one day to it?
    l
    m
    • 3
    • 5
  • v

    Vitali Plagov

    09/09/2020, 8:58 PM
    Can't understand, how can I subtract one day from a
    LocalDate
    ? There's a
    minus()
    function that takes
    LocalDate
    as an argument. But I can't understand, what should I pass in to subtract a particular period of time from it?
    i
    • 2
    • 2
  • f

    flosch

    09/12/2020, 9:13 PM
     An alternative JVM implementation for Android might be needed.
    It should be possible to use
    kotlinx-datetime
    on Android when targeting 26 and higher, right? I cannot seem to import anything from the
    kotlinx.datetime
    package. Anything else required for Android that is not mentioned here in the README?
    o
    • 2
    • 1
  • c

    Christian Dräger

    10/10/2020, 8:57 PM
    Hey I just tryed the kotlinx-datetime and was wandering if it has something like DateTime Formatter and how to use it. Any suggestions? To be more specific I just want to get the current date in a specific format (dd.MM.yyyy) as well as the current time (HH🇲🇲ss) as strings
    m
    b
    • 3
    • 2
  • b

    Bohdan Yevtushenko

    10/15/2020, 1:54 PM
    Hello, can I use this library when I have KMP project with IOS as well?
    i
    • 2
    • 4
  • m

    Mateusz Krawczuk

    10/22/2020, 10:46 AM
    Hi! I'm migrating some logic of my application to multiplatform using kotlinx-datetime, but I have question how can I get first day of the month to compare with other value? This is old kotlin code:
    val init = myDeviceModel.initTimestamp * 1000
                var date = LocalDate().withDayOfMonth(1).toDate()
                if (init > date.time) {
                    date = Date(init)
                }
    • 1
    • 1
  • j

    Jan Skrasek

    10/25/2020, 7:22 AM
    I miss some function which would tell me if year is leap. Did I miss something or it is really missing?
    👀 1
    i
    • 2
    • 4
  • n

    Nikky

    10/27/2020, 10:26 AM
    so
    Clock.System.now().toEpochMilliseconds()
    is the equivalent of
    System.getCurrentMillis()
    ?
    :yes: 1
    i
    l
    m
    • 4
    • 24
  • d

    dgngulcan

    11/11/2020, 7:05 PM
    now that
    Clock
    is deprecated, how can I get current date in KMM module?
    m
    • 2
    • 2
  • d

    Darren Bell

    11/19/2020, 4:10 PM
    Hi. Is there any examples of serialization? For example with @Serializable Thanks
    m
    j
    j
    • 4
    • 3
  • l

    leandro

    12/17/2020, 12:01 AM
    I (think that I) want to write a test that asserts that a specific amount of Duration has passed, but unsure how to do it. Or, in different words: given an Instant, I would like to simulate running in the future. Do I need some kind of mutable Clock, or should I use timeMark?
    j
    m
    • 3
    • 9
  • l

    leandro

    01/19/2021, 4:07 PM
    How one can add a month to an Instant? I’m currently doing something like:
    myInstant
          .toLocalDateTime(TimeZone.currentSystemDefault())
          .date.plus(DateTimeUnit.DateBased.MonthBased(1)).atStartOfDayIn(TimeZone.currentSystemDefault()),
    Edit: Solved, went with
    .plus(DateTimePeriod(months = 1), TimeZone.currentSystemDefault())
    m
    • 2
    • 1
  • p

    Paul Woitaschek

    01/25/2021, 10:02 AM
    We are seeing a crash on iOS where ios seems to send and old timezone,
    US/Pacific
    kotlin.RuntimeException: Unable to acquire the offset at instant 2021-01-20T15:59:38.842138051Z for zone US/Pacific
    I don't fully understand what's happening here. Our ios dev says this is related to this issue: https://stackoverflow.com/questions/19819268/convert-ios-localtimezone-to-a-knowntimezone The ios stacktraces aren't present for release frameworks but I think it boils down to this line of code:
    Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
    • 1
    • 1
  • p

    Paul Woitaschek

    01/25/2021, 5:45 PM
    What we found annoying so far with the DateTimeUnit things is that they throw an exception on duration=0. We have code where we have a dynamic amount of days added:
    loopDate.plus(DateTimeUnit.DateBased.DayBased(fastingDays.size))
    Now this throws:
    java.lang.IllegalArgumentException: Unit duration must be positive, but was 0 days.
    	at kotlinx.datetime.DateTimeUnit$DateBased$DayBased.<init>(DateTimeUnit.kt:68)
    Instead I would prefer to have the function just return the initial date instead of throwing when adding 0 dates. Now we always need to write != 0 checks everywhere and use the initial instance
    m
    • 2
    • 5
  • c

    chi

    01/31/2021, 3:41 PM
    Any idea how I can derive the first and last day of the week?
    i
    • 2
    • 2
  • w

    why

    02/05/2021, 4:49 PM
    Hi.. how can I add the library to my android project, I keep getting this error, it can’t find the artifact, any idea?
    Could not resolve all files for configuration ':android:debugRuntimeClasspath'.
       > Could not find org.jetbrains.kotlinx:kotlinx-datetime:0.1.1.
         Searched in the following locations:
           - <https://dl.google.com/dl/android/maven2/org/jetbrains/kotlinx/kotlinx-datetime/0.1.1/kotlinx-datetime-0.1.1.pom>
           - <https://jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-datetime/0.1.1/kotlinx-datetime-0.1.1.pom>
           - <https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-datetime/0.1.1/kotlinx-datetime-0.1.1.pom>
    j
    i
    • 3
    • 4
  • c

    cafonsomota

    03/27/2021, 1:17 AM
    Hello all! I’m using kotlinx-datetime in a project, and I’ve noticed something odd here in my side. I’m converting a
    Calendar
    object to
    LocalDateTime
    (kotlinx) by setting the
    year
    ,
    month
    , etc. on the constructor; and I’ve noticed that when I call
    .toString
    it prints something like 2021-03-27T09:00 instead of 2021-03-27T09:00:00Z. What I might be doing wrong?
    j
    i
    • 3
    • 4
  • p

    Paul Woitaschek

    03/31/2021, 10:43 AM
    What's the timeframe work 0.2.0? https://github.com/Kotlin/kotlinx-datetime/issues/94 This issue causes thousand of crashes for us 😕 Is there a snapshot repository somewhere available for the master versions?
    i
    • 2
    • 3
  • j

    Javier

    04/04/2021, 9:32 PM
    Is it possible to parse
    2014-06-10T16:12:58-0400
    ?
    o
    j
    • 3
    • 10
  • m

    Marc Knaup

    04/14/2021, 8:32 PM
    Does updating to Kotlin 1.5 cause a binary incompatibility with libraries that use
    kotlinx-datetime
    and are compiled with 1.4?
    I guess
    kotlinx-datetime
    isn’t actually compatible with Kotlin 1.5? 😱 Must be the change of
    Duration
    from
    Double
    to
    Long
    .
    java.lang.NoSuchMethodError: ‘kotlinx.datetime.Instant kotlinx.datetime.Instant.plus-LRDsOJo(long)’
    i
    p
    h
    • 4
    • 15
  • n

    Nikky

    04/23/2021, 7:55 AM
    does kotlinx-datetime have a way to get a date from the weeknumber ? i found a workaround using
    java.util.Calendar
    but i am not happy about it
    fun getMondayOfWeek(year: Int, week: Int): LocalDate {
        val cal = Calendar.getInstance()
        cal.set(Calendar.WEEK_OF_YEAR, week)
        cal.set(Calendar.YEAR, year)
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
        return cal.time.toInstant().toKotlinInstant().toLocalDateTime(systemTZ).date
    }
    is there a better way ?
    i
    o
    • 3
    • 4
  • k

    KamilH

    04/23/2021, 8:41 AM
    Can we expect a support to custom formats of the date? I saw this issue: https://github.com/Kotlin/kotlinx-datetime/issues/58 but no comments are there so I’m curious if such a feature is planned for any of the near releases
    i
    • 2
    • 1
  • d

    dave08

    05/10/2021, 3:10 PM
    Hi! Wouldn't it be nice to have the Clock interface declared as a
    fun interface
    ? That would allow very simple overriding of
    now()
    in unit tests... unless there are plans to add other functions to it?
    i
    p
    • 3
    • 6
  • m

    Marc Knaup

    05/25/2021, 2:34 PM
    If this is a deliberate change in Kotlin (expect enums no longer exhaustive) then please don’t use
    expect enum
    in
    kotlinx-datetime
    😕 https://github.com/Kotlin/kotlinx-datetime/issues/96
    i
    • 2
    • 5
  • m

    Marc Knaup

    05/25/2021, 3:25 PM
    Inconsistent:
    kotlinx-datetime
    Instant
    ,
    LocalDate
    , etc. • uses ISO-8601 for `toString()`/`parse()` • provides serializer
    kotlin.time
    Duration
    OTOH • uses human-readable output for
    toString()
    , returns ISO-8601 for
    toIsoString()
    , and has no
    parse()
    • has no serializer Still two different date/time worlds in Kotlin and usage is confusing and error-prone.
    😔 1
    i
    l
    • 3
    • 6
  • l

    LastExceed

    05/29/2021, 7:07 PM
    message has been deleted
    m
    • 2
    • 2
  • n

    Nikky

    06/10/2021, 12:41 PM
    seems like on JS the toString() function adds 3 digits but on JVM it does 8 to the fractional seconds is there a way to configure it to be consistent ?
    i
    • 2
    • 1
  • i

    iamthevoid

    06/25/2021, 7:18 AM
    I try to add value to instant. When i do this i get error [1]. But it looks strange because looks like method
    plus
    defined in
    Instant.kt
    [2]. How i can handle this problem?
    i
    • 2
    • 3
Powered by Linen
Title
i

iamthevoid

06/25/2021, 7:18 AM
I try to add value to instant. When i do this i get error [1]. But it looks strange because looks like method
plus
defined in
Instant.kt
[2]. How i can handle this problem?
2021-06-25 10:16:17.962 8268-8268/ru.rt.mlk.android.debug E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ru.rt.mlk.android.debug, PID: 8268
    java.lang.NoSuchMethodError: No virtual method plus-LRDsOJo(J)Lkotlinx/datetime/Instant; in class Lkotlinx/datetime/Instant; or its super classes (declaration of 'kotlinx.datetime.Instant' appears in /data/app/ru.rt.mlk.android.debug-g5W8-V28KcgbkTFVKV32LQ==/base.apk!classes26.dex)
        at ru.rt.mlk.shared.data.authorization.LoginRepositoryImpl.updateAuthData(LoginRepositoryImpl.kt:42)
        at ru.rt.mlk.shared.data.authorization.LoginApiImpl.onAuthTokenResponse(LoginApiImpl.kt:50)
        at ru.rt.mlk.shared.data.authorization.LoginApiImpl.authorize(LoginApiImpl.kt:33)
        at ru.rt.mlk.login.domain.interactor.LoginInteractorImpl.ssoLogin(LoginInteractorImpl.kt:16)
        at ru.rt.mlk.login.state.LoginScreenEventManagingKt$authorize$2.invokeSuspend(LoginScreenEventManaging.kt:13)
        at ru.rt.mlk.login.state.LoginScreenEventManagingKt$authorize$2.invoke(Unknown Source:8)
        at ru.rt.mlk.login.state.LoginScreenEventManagingKt$authorize$2.invoke(Unknown Source:2)
        at ru.rt.mlk.dkmp.utils.EventsManagerExtensionsKt$runOnIo$2.invokeSuspend(EventsManagerExtensions.kt:21)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
actual operator fun plus(duration: Duration): Instant = duration.toComponents { secondsToAdd, nanosecondsToAdd ->
        try {
            plus(secondsToAdd, nanosecondsToAdd.toLong())
        } catch (e: IllegalArgumentException) {
            if (secondsToAdd > 0) MAX else MIN
        } catch (e: ArithmeticException) {
            if (secondsToAdd > 0) MAX else MIN
        }
    }
i

ilya.gorbunov

06/25/2021, 11:00 AM
It's likely that you use different versions of kotlinx-datetime in compile time and in run time, for example, one is 0.1.x and another is 0.2.x.
👍 1
View count: 17