From ca17ef8d7c008a13d62bed628636ec159e8f6551 Mon Sep 17 00:00:00 2001
From: Sendil Kumar <sendilkumarn@live.com>
Date: Mon, 25 Jun 2018 10:14:00 +0200
Subject: [PATCH] Add date to string

---
 src/js.rs                    |  7 +++++++
 tests/all/js_globals/Date.rs | 27 +++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/src/js.rs b/src/js.rs
index cca47548..c1f34939 100644
--- a/src/js.rs
+++ b/src/js.rs
@@ -377,6 +377,13 @@ extern {
 extern {
     pub type Date;
 
+    /// The toString() method returns a string representing
+    /// the specified Date object.
+    ///
+    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString
+    #[wasm_bindgen(method, js_name = toString)]
+    pub fn to_string(this: &Date) -> JsString;
+
     /// The toTimeString() method returns the time portion of a Date object in human
     /// readable form in American English.
     ///
diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs
index e17659fb..eaf551fd 100644
--- a/tests/all/js_globals/Date.rs
+++ b/tests/all/js_globals/Date.rs
@@ -2,6 +2,33 @@
 
 use super::project;
 
+#[test]
+fn to_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_string(this: &Date) -> JsString {
+                this.to_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_string(date).substring(0, 15), "Tue Aug 19 1975");
+            }
+        "#)
+        .test()
+}
+
 #[test]
 fn to_time_string() {
     project()