ref #34 time formatting and precision time access
This commit is contained in:
1 parent
732d8f3877
commit
230cb0a067
8 files changed
+108
-14
No files matched your search
@@ -33,10 +33,6 @@ open class ObjClass(
|
||||
return instance
|
||||
}
|
||||
|
||||
// fun defaultInstance(): Obj = object : Obj() {
|
||||
// override val objClass: ObjClass = this@ObjClass
|
||||
// }
|
||||
|
||||
fun createField(
|
||||
name: String,
|
||||
initialValue: Obj,
|
||||
|
||||
@@ -56,6 +56,11 @@ class ObjDuration(val duration: Duration) : Obj() {
|
||||
addFn("milliseconds") {
|
||||
thisAs<ObjDuration>().duration.toDouble(DurationUnit.MILLISECONDS).toObj()
|
||||
}
|
||||
addFn("microseconds") {
|
||||
thisAs<ObjDuration>().duration.toDouble(DurationUnit.MICROSECONDS).toObj()
|
||||
}
|
||||
// extensions
|
||||
|
||||
ObjInt.type.addFn("seconds") {
|
||||
ObjDuration(thisAs<ObjInt>().value.seconds)
|
||||
}
|
||||
@@ -63,7 +68,6 @@ class ObjDuration(val duration: Duration) : Obj() {
|
||||
ObjInt.type.addFn("second") {
|
||||
ObjDuration(thisAs<ObjInt>().value.seconds)
|
||||
}
|
||||
|
||||
ObjInt.type.addFn("milliseconds") {
|
||||
ObjDuration(thisAs<ObjInt>().value.milliseconds)
|
||||
}
|
||||
@@ -71,7 +75,6 @@ class ObjDuration(val duration: Duration) : Obj() {
|
||||
ObjInt.type.addFn("millisecond") {
|
||||
ObjDuration(thisAs<ObjInt>().value.milliseconds)
|
||||
}
|
||||
|
||||
ObjReal.type.addFn("seconds") {
|
||||
ObjDuration(thisAs<ObjReal>().value.seconds)
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ class ObjInstant(val instant: Instant) : Obj() {
|
||||
return super.compareTo(scope, other)
|
||||
}
|
||||
|
||||
override suspend fun toKotlin(scope: Scope): Any {
|
||||
return instant
|
||||
}
|
||||
|
||||
companion object {
|
||||
val distantFuture by lazy {
|
||||
ObjInstant(Instant.DISTANT_FUTURE)
|
||||
@@ -51,7 +55,7 @@ class ObjInstant(val instant: Instant) : Obj() {
|
||||
when (a0) {
|
||||
null -> {
|
||||
val t = Clock.System.now()
|
||||
Instant.fromEpochSeconds(t.epochSeconds, (t.nanosecondsOfSecond / 1_000_000).toLong()*1_000_000)
|
||||
Instant.fromEpochSeconds(t.epochSeconds, t.nanosecondsOfSecond)
|
||||
}
|
||||
is ObjInt -> Instant.fromEpochSeconds(a0.value)
|
||||
is ObjReal -> {
|
||||
@@ -78,6 +82,14 @@ class ObjInstant(val instant: Instant) : Obj() {
|
||||
addFn("isDistantPast") {
|
||||
thisAs<ObjInstant>().instant.isDistantPast.toObj()
|
||||
}
|
||||
addFn("epochWholeSeconds") {
|
||||
ObjInt(thisAs<ObjInstant>().instant.epochSeconds)
|
||||
}
|
||||
addFn("nanosecondsOfSecond") {
|
||||
ObjInt(thisAs<ObjInstant>().instant.nanosecondsOfSecond.toLong())
|
||||
}
|
||||
// class members
|
||||
|
||||
addClassConst("distantFuture", distantFuture)
|
||||
addClassConst("distantPast", distantPast)
|
||||
// addFn("epochMilliseconds") {
|
||||
|
||||
Reference in new issue
Block a user