using Php;

namespace PhpNative {
    public double microtime_float_static (string php_file, int php_line) throws Error {
        int64 usec = GLib.get_real_time ();
        return ((double) usec) / 1000000.0;
    }

    public string microtime_string_static (string php_file, int php_line) throws Error {
        int64 usec = GLib.get_real_time ();
        int64 seconds = usec / 1000000;
        int64 micros = usec % 1000000;
        return "0.%06d %s".printf ((int) micros, seconds.to_string ());
    }

    public zval microtime_zval (zval as_float, string php_file, int php_line) throws Error {
        if (truthy (as_float)) {
            return zval.double_number (microtime_float_static (php_file, php_line));
        }
        return zval.string_value (microtime_string_static (php_file, php_line));
    }
}
