mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-01 18:01:06 +00:00
Add date to time string
This commit is contained in:
parent
033ba3f3a7
commit
f30de17c2b
@ -377,6 +377,13 @@ extern {
|
|||||||
extern {
|
extern {
|
||||||
pub type Date;
|
pub type Date;
|
||||||
|
|
||||||
|
/// The toTimeString() method returns the time portion of a Date object in human
|
||||||
|
/// readable form in American English.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString
|
||||||
|
#[wasm_bindgen(method, js_name = toTimeString)]
|
||||||
|
pub fn to_time_string(this: &Date) -> JsString;
|
||||||
|
|
||||||
/// The toUTCString() method converts a date to a string,
|
/// The toUTCString() method converts a date to a string,
|
||||||
/// using the UTC time zone.
|
/// using the UTC time zone.
|
||||||
///
|
///
|
||||||
|
@ -2,6 +2,33 @@
|
|||||||
|
|
||||||
use super::project;
|
use super::project;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_time_string() {
|
||||||
|
project()
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js::{Date, JsString};
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn to_time_string(this: &Date) -> JsString {
|
||||||
|
this.to_time_string()
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let date = new Date('August 19, 1975 23:15:30');
|
||||||
|
assert.equal(wasm.to_time_string(date).substring(0, 8), "23:15:30");
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_utc_string() {
|
fn to_utc_string() {
|
||||||
project()
|
project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user