nixMain.io.ktor.util.date.DateNix.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktor-utils-watchosarm64 Show documentation
Show all versions of ktor-utils-watchosarm64 Show documentation
Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.util.date
import kotlinx.cinterop.*
import platform.posix.*
@Suppress("FunctionName")
@OptIn(UnsafeNumber::class)
internal actual fun system_time(tm: CValuesRef?): Long = timegm(tm).convert()
/**
* Gets current system time in milliseconds since a certain moment in the past,
* only delta between two subsequent calls makes sense.
*/
@OptIn(UnsafeNumber::class)
public actual fun getTimeMillis(): Long = memScoped {
val timeHolder = alloc()
clock_gettime(CLOCK_REALTIME.convert(), timeHolder.ptr)
timeHolder.tv_sec * 1000L + timeHolder.tv_nsec / 1000000L
}