mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Add initial Date bindings
Doesn't do much, yet, because we can't get the timezone with a plain binding, but it's at least something.
This commit is contained in:
10
std/assembly/bindings/Date.ts
Normal file
10
std/assembly/bindings/Date.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export declare function UTC(
|
||||
year: i32,
|
||||
month: i32,
|
||||
day: i32,
|
||||
hour: i32,
|
||||
minute: i32,
|
||||
second: i32,
|
||||
millisecond: i32
|
||||
): f64;
|
||||
export declare function now(): f64;
|
37
std/assembly/date.ts
Normal file
37
std/assembly/date.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import {
|
||||
UTC as Date_UTC,
|
||||
now as Date_now
|
||||
} from "./bindings/Date";
|
||||
|
||||
export class Date {
|
||||
|
||||
@inline static UTC(
|
||||
year: i32,
|
||||
month: i32 = 0,
|
||||
day: i32 = 1,
|
||||
hour: i32 = 0,
|
||||
minute: i32 = 0,
|
||||
second: i32 = 0,
|
||||
millisecond: i32 = 0
|
||||
): i64 {
|
||||
return <i64>Date_UTC(year, month, day, hour, minute, second, millisecond);
|
||||
}
|
||||
|
||||
@inline static now(): i64 {
|
||||
return <i64>Date_now();
|
||||
}
|
||||
|
||||
private value: i64;
|
||||
|
||||
constructor(value: i64) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
getTime(): i64 {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
setTime(value: i64): void {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
21
std/assembly/index.d.ts
vendored
21
std/assembly/index.d.ts
vendored
@ -657,6 +657,27 @@ declare const Math: IMath<f64>;
|
||||
/** Alias of {@link NativeMathf} or {@link JSMath} respectively. Defaults to `NativeMathf`. */
|
||||
declare const Mathf: IMath<f32>;
|
||||
|
||||
declare class Date {
|
||||
/** Returns the UTC timestamp in milliseconds of the specified date. */
|
||||
static UTC(
|
||||
year: i32,
|
||||
month: i32,
|
||||
day: i32,
|
||||
hour: i32,
|
||||
minute: i32,
|
||||
second: i32,
|
||||
millisecond: i32
|
||||
): i64;
|
||||
/** Returns the current UTC timestamp in milliseconds. */
|
||||
static now(): i64;
|
||||
/** Constructs a new date object from an UTC timestamp in milliseconds. */
|
||||
constructor(value: i64);
|
||||
/** Returns the UTC timestamp of this date in milliseconds. */
|
||||
getTime(): i64;
|
||||
/** Sets the UTC timestamp of this date in milliseconds. */
|
||||
setTime(value: i64): void;
|
||||
}
|
||||
|
||||
/** Environmental tracing function for debugging purposes. */
|
||||
declare function trace(msg: string, n?: i32, a0?: f64, a1?: f64, a2?: f64, a3?: f64, a4?: f64): void;
|
||||
|
||||
|
21
std/portable/index.d.ts
vendored
21
std/portable/index.d.ts
vendored
@ -424,6 +424,27 @@ declare const Math: IMath;
|
||||
declare const Mathf: IMath;
|
||||
declare const JSMath: IMath;
|
||||
|
||||
declare class Date {
|
||||
/** Returns the UTC timestamp in milliseconds of the specified date. */
|
||||
static UTC(
|
||||
year: i32,
|
||||
month: i32,
|
||||
day: i32,
|
||||
hour: i32,
|
||||
minute: i32,
|
||||
second: i32,
|
||||
millisecond: i32
|
||||
): number;
|
||||
/** Returns the current UTC timestamp in milliseconds. */
|
||||
static now(): number;
|
||||
/** Constructs a new date object from an UTC timestamp in milliseconds. */
|
||||
constructor(value: number);
|
||||
/** Returns the UTC timestamp of this date in milliseconds. */
|
||||
getTime(): number;
|
||||
/** Sets the UTC timestamp of this date in milliseconds. */
|
||||
setTime(value: number): void;
|
||||
}
|
||||
|
||||
declare namespace console {
|
||||
/** @deprecated */
|
||||
function log(message: string): void;
|
||||
|
Reference in New Issue
Block a user