Mark ab/7061308 as merged in stage.

Bug: 180401296
Merged-In: Id5737bba7df51ee3c84c339917f59b00d9f283f6
Change-Id: I55897da0695e3ef760a98e73f56cd9da9dd17d92
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index cd27d63..0fa03ad 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "3819881b22c13652f3d625f6e7668ccfb2bd27bd"
+    "sha1": "eff71cffcc21f0b6d84a7dc3009cacb9ff16b4ea"
   }
 }
diff --git a/Android.bp b/Android.bp
index e600e2a..4d1f5e3 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,5 +1,22 @@
 // This file is generated by cargo2android.py --run --device --dependencies.
 
+package {
+    default_applicable_licenses: ["external_rust_crates_instant_license"],
+}
+
+// Added automatically by a large-scale-change
+// See: http://go/android-license-faq
+license {
+    name: "external_rust_crates_instant_license",
+    visibility: [":__subpackages__"],
+    license_kinds: [
+        "SPDX-license-identifier-BSD",
+    ],
+    license_text: [
+        "LICENSE",
+    ],
+}
+
 rust_library {
     name: "libinstant",
     host_supported: true,
diff --git a/Cargo.toml b/Cargo.toml
index d11b2d3..58dea4e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
 [package]
 edition = "2018"
 name = "instant"
-version = "0.1.8"
+version = "0.1.9"
 authors = ["sebcrozet <developer@crozet.re>"]
 description = "A partial replacement for std::time::Instant that works on WASM too."
 readme = "README.md"
@@ -26,6 +26,7 @@
 version = "0.3"
 
 [features]
+inaccurate = []
 now = ["time"]
 wasm-bindgen = ["js-sys", "wasm-bindgen_rs", "web-sys"]
 [target.asmjs-unknown-emscripten.dependencies.js-sys]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 8a7047e..f6be57f 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "instant"
-version = "0.1.8"
+version = "0.1.9"
 authors = ["sebcrozet <developer@crozet.re>"]
 description = "A partial replacement for std::time::Instant that works on WASM too."
 repository = "https://github.com/sebcrozet/instant"
@@ -12,6 +12,7 @@
 [features]
 now = [ "time" ]
 wasm-bindgen = ["js-sys", "wasm-bindgen_rs", "web-sys"]
+inaccurate = []
 
 [dependencies]
 cfg-if = "1.0"
diff --git a/METADATA b/METADATA
index d0a96d7..c8d8100 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/instant/instant-0.1.8.crate"
+    value: "https://static.crates.io/crates/instant/instant-0.1.9.crate"
   }
-  version: "0.1.8"
+  version: "0.1.9"
   license_type: NOTICE
   last_upgrade_date {
     year: 2020
-    month: 10
-    day: 26
+    month: 11
+    day: 19
   }
 }
diff --git a/README.md b/README.md
index 28f6bdd..ecda215 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,26 @@
 
 -----
 
+### Using `instant` for a WASM platform where `performance.now()` is not available.
+This example shows the use of the `inaccurate` feature.
+
+_Cargo.toml_:
+```toml
+[dependencies]
+instant = { version = "0.1", features = [ "wasm-bindgen", "inaccurate" ] }
+```
+
+_main.rs_:
+```rust
+fn main() {
+    // Will emulate `std::time::Instant` based on `Date.now()`.
+    let now = instant::Instant::new();
+}
+```
+
+
+-----
+
 ### Using `instant` for any platform enabling a feature transitively.
 _Cargo.toml_:
 ```toml
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 5058d5e..7213fe9 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1,11 +1,7 @@
-// Generated by cargo2android.py for tests in Android.bp
+// Generated by cargo2android.py for tests that depend on this crate.
 {
   "presubmit": [
     {
-      "host": true,
-      "name": "parking_lot_core_host_test_src_lib"
-    },
-    {
       "name": "parking_lot_core_device_test_src_lib"
     }
   ]
diff --git a/src/wasm.rs b/src/wasm.rs
index 829ef3b..986bbf6 100644
--- a/src/wasm.rs
+++ b/src/wasm.rs
@@ -101,18 +101,27 @@
     use stdweb::unstable::TryInto;
 
     // https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
+    #[cfg(not(feature = "inaccurate"))]
     let v = js! { return performance.now(); };
+    #[cfg(feature = "inaccurate")]
+    let v = js! { return Date.now(); };
     v.try_into().unwrap()
 }
 
 #[cfg(feature = "wasm-bindgen")]
 pub fn now() -> f64 {
-    use wasm_bindgen_rs::prelude::*;
-    use wasm_bindgen_rs::JsCast;
-    js_sys::Reflect::get(&js_sys::global(), &JsValue::from_str("performance"))
-        .expect("failed to get performance from global object")
-        .unchecked_into::<web_sys::Performance>()
-        .now()
+    #[cfg(not(feature = "inaccurate"))]
+    let now = {
+        use wasm_bindgen_rs::prelude::*;
+        use wasm_bindgen_rs::JsCast;
+        js_sys::Reflect::get(&js_sys::global(), &JsValue::from_str("performance"))
+            .expect("failed to get performance from global object")
+            .unchecked_into::<web_sys::Performance>()
+            .now()
+    };
+    #[cfg(feature = "inaccurate")]
+    let now = js_sys::Date::now();
+    now
 }
 
 // The JS now function is in a module so it won't have to be renamed
diff --git a/tests/wasm.rs b/tests/wasm.rs
index b1577ad..863eefd 100644
--- a/tests/wasm.rs
+++ b/tests/wasm.rs
@@ -10,6 +10,9 @@
 #[wasm_bindgen_test]
 fn test_instant_now() {
     let now = Instant::now();
+    #[cfg(feature = "inaccurate")]
+    while now.elapsed().as_millis() == 0 {}
+    #[cfg(not(feature = "inaccurate"))]
     assert!(now.elapsed().as_nanos() > 0);
 }