All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nixMain.io.ktor.util.date.DateNix.kt Maven / Gradle / Ivy

Go to download

Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.

There is a newer version: 3.0.0-rc-1
Show newest version
/*
 * 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
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy