avm2: Implement toUTCString

This commit is contained in:
EmperorBale 2021-07-28 18:04:01 -07:00 committed by Adrian Wielgosik
parent 292a9bda4b
commit 10be7ef3bf
1 changed files with 22 additions and 0 deletions

View File

@ -942,6 +942,27 @@ pub fn to_string<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
/// Implements the `toUTCString` method.
pub fn to_utc_string<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(this) = this.and_then(|this| this.as_date_object()) {
if let Some(date) = this.date_time() {
return Ok(AvmString::new(
activation.context.gc_context,
date.format("%a %b %-d %T %-Y UTC").to_string(),
)
.into());
} else {
return Ok("Invalid Date".into());
}
}
Ok(Value::Undefined)
}
/// Implements the `toLocaleString` method. /// Implements the `toLocaleString` method.
pub fn to_locale_string<'gc>( pub fn to_locale_string<'gc>(
activation: &mut Activation<'_, 'gc, '_>, activation: &mut Activation<'_, 'gc, '_>,
@ -1117,6 +1138,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
("getTimezoneOffset", timezone_offset), ("getTimezoneOffset", timezone_offset),
("valueOf", time), ("valueOf", time),
("toString", to_string), ("toString", to_string),
("toUTCString", to_utc_string),
("toLocaleString", to_locale_string), ("toLocaleString", to_locale_string),
("toTimeString", to_time_string), ("toTimeString", to_time_string),
("toLocaleTimeString", to_locale_time_string), ("toLocaleTimeString", to_locale_time_string),