//package std::time;

//Private functions, you can only use "Time" related functions through the public interface (Time class)
private extern now() -> Time;
private extern format_time(t: Time, fmt: string) -> string;
private extern sleep(t: Time);


public struct Time {
public:
    sec: int64;
    nsec: int64;
public:
    Time(sec: int64, nsec: int64) {
        this.sec = sec;
        this.nsec = nsec;
    }
    ~Time() {}
    fun to_iso_string(this) -> string {
        return format_time(this, "%Y-%m-%dT%H:%M:%S");
    }
    fun format(this, fmt: const string) -> string {
        return format_time(this, fmt);
    }
    fun now() -> Time {
        return now();
    }
    fun elapsed(this, since: Time) -> Time {
        let sec_diff = this.sec - since.sec;
        let nsec_diff = this.nsec - since.nsec;
        if nsec_diff < 0 {
            return Time(sec_diff - 1, nsec_diff + 1_000_000_000);
        }
        return Time(sec_diff, nsec_diff);
    }
    fun sleep(this) {
        sleep(this);
    }
}
