From ee7131939a7d074ffef7f54678a1fb0bc9aab4d4 Mon Sep 17 00:00:00 2001 From: OpenActive Bot <20357321+openactive-bot@users.noreply.github.com> Date: Wed, 3 Mar 2021 19:31:19 +0000 Subject: [PATCH] Fix startDate and endDate for ScheduledSessions and Slots (#26) --- OpenActive.NET.Test/OrderTest.cs | 8 +++---- OpenActive.NET/models/ScheduledSession.cs | 27 ++++++++++++++++++++++- OpenActive.NET/models/SessionSeries.cs | 8 ++++++- OpenActive.NET/models/Slot.cs | 12 +++++----- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/OpenActive.NET.Test/OrderTest.cs b/OpenActive.NET.Test/OrderTest.cs index 378f11c..b23eb9b 100644 --- a/OpenActive.NET.Test/OrderTest.cs +++ b/OpenActive.NET.Test/OrderTest.cs @@ -197,7 +197,9 @@ public void OrderQuote_EncodeDecode() "\"orderedItem\":{" + "\"@type\":\"ScheduledSession\"," + "\"@id\":\"https://example.com/events/452/subEvents/132\"," + + "\"startDate\":\"2018-10-30T11:00:00+00:00\"," + "\"identifier\":123," + + "\"endDate\":\"2018-10-30T12:00:00+00:00\"," + "\"superEvent\":{" + "\"@type\":\"SessionSeries\"," + "\"@id\":\"https://example.com/events/452\"," + @@ -228,9 +230,7 @@ public void OrderQuote_EncodeDecode() "}" + "}," + "\"duration\":\"PT1H\"," + - "\"eventStatus\":\"https://schema.org/EventScheduled\"," + - "\"startDate\":\"2018-10-30T11:00:00+00:00\"," + - "\"endDate\":\"2018-10-30T12:00:00+00:00\"" + + "\"eventStatus\":\"https://schema.org/EventScheduled\"" + "}," + "\"orderItemStatus\":\"https://openactive.io/OrderItemConfirmed\"," + "\"unitTaxSpecification\":[" + @@ -331,7 +331,7 @@ public void Order_Deserialize_Accessors() Assert.Equal("Geoff", order?.Customer.GivenName); Assert.Equal("EUCODE", order?.OrderedItem?[0]?.UnitTaxSpecification?[0]?.Identifier.GetClass<List<PropertyValue>>()?[0].Name); Assert.Equal(new TimeSpan(6,0,0,0), order?.OrderedItem?[0]?.AcceptedOffer?.ValidFromBeforeStartDate); - Assert.Equal(new DateTimeOffset(2018, 10, 30, 11, 00, 00, 00, new TimeSpan()), order?.OrderedItem?[0]?.OrderedItem?.StartDate.GetPrimative<DateTimeOffset>()); + Assert.Equal(new DateTimeOffset(2018, 10, 30, 11, 00, 00, 00, new TimeSpan()), ((ScheduledSession)order?.OrderedItem?[0]?.OrderedItem)?.StartDate); } [Fact] diff --git a/OpenActive.NET/models/ScheduledSession.cs b/OpenActive.NET/models/ScheduledSession.cs index f327af6..d35c141 100644 --- a/OpenActive.NET/models/ScheduledSession.cs +++ b/OpenActive.NET/models/ScheduledSession.cs @@ -44,13 +44,38 @@ public override string ToString() [DataMember(Name = "@type", Order = 1)] public override string Type => "ScheduledSession"; + /// <summary> + /// The start date and time of the event. + /// </summary> + /// <example> + /// <code> + /// "startDate": "2018-01-27T12:00:00Z" + /// </code> + /// </example> + [DataMember(Name = "startDate", EmitDefaultValue = false, Order = 7)] + [JsonConverter(typeof(OpenActiveDateTimeOffsetToISO8601DateTimeValuesConverter))] + public new virtual DateTimeOffset? StartDate { get; set; } + + /// <summary> + /// The end date and time of the event. + /// It is recommended that publishers provide either an schema:endDate or a schema:duration for an event. + /// </summary> + /// <example> + /// <code> + /// "endDate": "2018-01-27T12:00:00Z" + /// </code> + /// </example> + [DataMember(Name = "endDate", EmitDefaultValue = false, Order = 8)] + [JsonConverter(typeof(OpenActiveDateTimeOffsetToISO8601DateTimeValuesConverter))] + public new virtual DateTimeOffset? EndDate { get; set; } + [Obsolete("This property is disinherited in this type, and must not be used.", true)] public override List<Event> SubEvent { get; set; } /// <summary> /// Relates a child event to a parent event. Properties describing the parent event can be assumed to apply to the child, unless otherwise specified. A parent event might specify a recurring schedule, of which the child event is one specific instance /// </summary> - [DataMember(Name = "superEvent", EmitDefaultValue = false, Order = 8)] + [DataMember(Name = "superEvent", EmitDefaultValue = false, Order = 10)] [JsonConverter(typeof(ValuesConverter))] public new virtual SingleValues<Uri, Event> SuperEvent { get; set; } } diff --git a/OpenActive.NET/models/SessionSeries.cs b/OpenActive.NET/models/SessionSeries.cs index 04946ef..669ee44 100644 --- a/OpenActive.NET/models/SessionSeries.cs +++ b/OpenActive.NET/models/SessionSeries.cs @@ -70,10 +70,16 @@ public override string ToString() [Obsolete("This property is disinherited in this type, and must not be used.", true)] public override long? RemainingAttendeeCapacity { get; set; } + [Obsolete("This property is disinherited in this type, and must not be used.", true)] + public override SingleValues<string, DateTimeOffset?> StartDate { get; set; } + + [Obsolete("This property is disinherited in this type, and must not be used.", true)] + public override SingleValues<string, DateTimeOffset?> EndDate { get; set; } + /// <summary> /// Relates a parent event to a child event. Properties describing the parent event can be assumed to apply to the child, unless otherwise specified. A child event might be a specific instance of an Event within a schedule /// </summary> - [DataMember(Name = "subEvent", EmitDefaultValue = false, Order = 9)] + [DataMember(Name = "subEvent", EmitDefaultValue = false, Order = 11)] [JsonConverter(typeof(ValuesConverter))] public new virtual List<ScheduledSession> SubEvent { get; set; } } diff --git a/OpenActive.NET/models/Slot.cs b/OpenActive.NET/models/Slot.cs index 305e987..2ac81f2 100644 --- a/OpenActive.NET/models/Slot.cs +++ b/OpenActive.NET/models/Slot.cs @@ -202,7 +202,7 @@ public override string ToString() public override string SchedulingNote { get; set; } /// <summary> - /// The start date and time of the slot. Can be specified as a schema:Date or schema:DateTime + /// The start date and time of the slot. /// </summary> /// <example> /// <code> @@ -210,11 +210,11 @@ public override string ToString() /// </code> /// </example> [DataMember(Name = "startDate", EmitDefaultValue = false, Order = 39)] - [JsonConverter(typeof(ValuesConverter))] - public override SingleValues<string, DateTimeOffset?> StartDate { get; set; } + [JsonConverter(typeof(OpenActiveDateTimeOffsetToISO8601DateTimeValuesConverter))] + public new virtual DateTimeOffset? StartDate { get; set; } /// <summary> - /// The end date and time of the slot. Can be specified as a schema:Date or schema:DateTime + /// The end date and time of the slot. /// It is recommended that publishers provide either an schema:endDate or a schema:duration for an slot. /// </summary> /// <example> @@ -223,8 +223,8 @@ public override string ToString() /// </code> /// </example> [DataMember(Name = "endDate", EmitDefaultValue = false, Order = 40)] - [JsonConverter(typeof(ValuesConverter))] - public override SingleValues<string, DateTimeOffset?> EndDate { get; set; } + [JsonConverter(typeof(OpenActiveDateTimeOffsetToISO8601DateTimeValuesConverter))] + public new virtual DateTimeOffset? EndDate { get; set; } [Obsolete("This property is disinherited in this type, and must not be used.", true)] public override List<Event> SubEvent { get; set; }