Skip to content

feat: sub-second now() on native via clock_gettime #2

Description

@brickfrog

Currently `DateTime::now()` on native uses POSIX `time(2)` — whole-second precision only.

Fix

Add a thin C stub calling `clock_gettime(CLOCK_REALTIME)` that returns nanoseconds as `Int64`. Replace the `time(2)` call in `now_native.mbt`.

```c
#include <time.h>
#include <stdint.h>

int64_t tempo_sys_unix_nanos(void) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec;
}
```

Requires wiring a `.c` file into the build via `moon.pkg` native link config. Need to verify the exact `moon.pkg` syntax for linking C sources — check moonbitlang/core for examples.

Acceptance

`DateTime::now()` returns millisecond (or better) precision on all three backends.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions