Browse Source

migrate from 'time' to 'chrono', fixes issue #3

pull/8/head
Hayden Hong 6 years ago
parent
commit
bd6feb681a
  1. 2
      Cargo.toml
  2. 8
      src/lib/js/console.rs
  3. 2
      src/lib/lib.rs

2
Cargo.toml

@ -15,7 +15,7 @@ gc = "0.3.2"
gc_derive = "0.3.2" gc_derive = "0.3.2"
serde_json = "1.0" serde_json = "1.0"
rand = "0.5.5" rand = "0.5.5"
time = "0.1" chrono = "0.4"
[lib] [lib]
name = "boa" name = "boa"

8
src/lib/js/console.rs

@ -2,14 +2,16 @@ use gc::Gc;
use crate::js::function::NativeFunctionData; use crate::js::function::NativeFunctionData;
use crate::js::value::{from_value, to_value, ResultValue, Value, ValueData}; use crate::js::value::{from_value, to_value, ResultValue, Value, ValueData};
use std::iter::FromIterator; use std::iter::FromIterator;
use time::{now, strftime}; use chrono::Local;
/// Print a javascript value to the standard output stream /// Print a javascript value to the standard output stream
pub fn log(_: Value, _: Value, args: Vec<Value>) -> ResultValue { pub fn log(_: Value, _: Value, args: Vec<Value>) -> ResultValue {
let args: Vec<String> = FromIterator::from_iter( let args: Vec<String> = FromIterator::from_iter(
args.iter() args.iter()
.map(|x| from_value::<String>(x.clone()).unwrap()), .map(|x| from_value::<String>(x.clone()).unwrap()),
); );
println!("{}: {}", strftime("%X", &now()).unwrap(), args.join(" "));
println!("{}: {}", Local::now().format("%X").to_string(), args.join(" "));
Ok(Gc::new(ValueData::Undefined)) Ok(Gc::new(ValueData::Undefined))
} }
/// Print a javascript value to the standard error stream /// Print a javascript value to the standard error stream
@ -18,7 +20,7 @@ pub fn error(_: Value, _: Value, args: Vec<Value>) -> ResultValue {
args.iter() args.iter()
.map(|x| from_value::<String>(x.clone()).unwrap()), .map(|x| from_value::<String>(x.clone()).unwrap()),
); );
eprintln!("{}: {}", strftime("%X", &now()).unwrap(), args.join(" ")); println!("{}: {}", Local::now().format("%X").to_string(), args.join(" "));
Ok(Gc::new(ValueData::Undefined)) Ok(Gc::new(ValueData::Undefined))
} }
/// Create a new `console` object /// Create a new `console` object

2
src/lib/lib.rs

@ -1,7 +1,7 @@
extern crate gc; extern crate gc;
extern crate rand; extern crate rand;
extern crate serde_json; extern crate serde_json;
extern crate time; extern crate chrono;
#[macro_use] #[macro_use]
extern crate gc_derive; extern crate gc_derive;

Loading…
Cancel
Save