mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	LibJS: Implement Temporal.ZonedDateTime.prototype.millisecond
This commit is contained in:
		
							parent
							
								
									9d9ab492df
								
							
						
					
					
						commit
						752b3eb0c0
					
				
					 3 changed files with 44 additions and 0 deletions
				
			
		|  | @ -39,6 +39,7 @@ void ZonedDateTimePrototype::initialize(GlobalObject& global_object) | ||||||
|     define_native_accessor(vm.names.hour, hour_getter, {}, Attribute::Configurable); |     define_native_accessor(vm.names.hour, hour_getter, {}, Attribute::Configurable); | ||||||
|     define_native_accessor(vm.names.minute, minute_getter, {}, Attribute::Configurable); |     define_native_accessor(vm.names.minute, minute_getter, {}, Attribute::Configurable); | ||||||
|     define_native_accessor(vm.names.second, second_getter, {}, Attribute::Configurable); |     define_native_accessor(vm.names.second, second_getter, {}, Attribute::Configurable); | ||||||
|  |     define_native_accessor(vm.names.millisecond, millisecond_getter, {}, Attribute::Configurable); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ZonedDateTime* typed_this(GlobalObject& global_object) | static ZonedDateTime* typed_this(GlobalObject& global_object) | ||||||
|  | @ -269,4 +270,31 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::second_getter) | ||||||
|     return Value(temporal_date_time->iso_second()); |     return Value(temporal_date_time->iso_second()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // 6.3.12 get Temporal.ZonedDateTime.prototype.millisecond, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.millisecond
 | ||||||
|  | JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::millisecond_getter) | ||||||
|  | { | ||||||
|  |     // 1. Let zonedDateTime be the this value.
 | ||||||
|  |     // 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
 | ||||||
|  |     auto* zoned_date_time = typed_this(global_object); | ||||||
|  |     if (vm.exception()) | ||||||
|  |         return {}; | ||||||
|  | 
 | ||||||
|  |     // 3. Let timeZone be zonedDateTime.[[TimeZone]].
 | ||||||
|  |     auto& time_zone = zoned_date_time->time_zone(); | ||||||
|  | 
 | ||||||
|  |     // 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
 | ||||||
|  |     auto* instant = create_temporal_instant(global_object, zoned_date_time->nanoseconds()); | ||||||
|  | 
 | ||||||
|  |     // 5. Let calendar be zonedDateTime.[[Calendar]].
 | ||||||
|  |     auto& calendar = zoned_date_time->calendar(); | ||||||
|  | 
 | ||||||
|  |     // 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
 | ||||||
|  |     auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar); | ||||||
|  |     if (vm.exception()) | ||||||
|  |         return {}; | ||||||
|  | 
 | ||||||
|  |     // 7. Return 𝔽(temporalDateTime.[[ISOMillisecond]]).
 | ||||||
|  |     return Value(temporal_date_time->iso_millisecond()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -28,6 +28,7 @@ private: | ||||||
|     JS_DECLARE_NATIVE_FUNCTION(hour_getter); |     JS_DECLARE_NATIVE_FUNCTION(hour_getter); | ||||||
|     JS_DECLARE_NATIVE_FUNCTION(minute_getter); |     JS_DECLARE_NATIVE_FUNCTION(minute_getter); | ||||||
|     JS_DECLARE_NATIVE_FUNCTION(second_getter); |     JS_DECLARE_NATIVE_FUNCTION(second_getter); | ||||||
|  |     JS_DECLARE_NATIVE_FUNCTION(millisecond_getter); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | describe("correct behavior", () => { | ||||||
|  |     test("basic functionality", () => { | ||||||
|  |         const timeZone = new Temporal.TimeZone("UTC"); | ||||||
|  |         const zonedDateTime = new Temporal.ZonedDateTime(123000000n, timeZone); | ||||||
|  |         expect(zonedDateTime.millisecond).toBe(123); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test("errors", () => { | ||||||
|  |     test("this value must be a Temporal.ZonedDateTime object", () => { | ||||||
|  |         expect(() => { | ||||||
|  |             Reflect.get(Temporal.ZonedDateTime.prototype, "millisecond", "foo"); | ||||||
|  |         }).toThrowWithMessage(TypeError, "Not a Temporal.ZonedDateTime"); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh