diff --git a/core/src/avm2/globals/date.rs b/core/src/avm2/globals/date.rs index ee70e35d1..9700cebd4 100644 --- a/core/src/avm2/globals/date.rs +++ b/core/src/avm2/globals/date.rs @@ -942,6 +942,27 @@ pub fn to_string<'gc>( Ok(Value::Undefined) } +/// Implements the `toUTCString` method. +pub fn to_utc_string<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, 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. pub fn to_locale_string<'gc>( activation: &mut Activation<'_, 'gc, '_>, @@ -1117,6 +1138,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> ("getTimezoneOffset", timezone_offset), ("valueOf", time), ("toString", to_string), + ("toUTCString", to_utc_string), ("toLocaleString", to_locale_string), ("toTimeString", to_time_string), ("toLocaleTimeString", to_locale_time_string),