Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
<AutoGen>True</AutoGen>
<DependentUpon>TextUtf8RawTextWriter.tt</DependentUpon>
</Compile>
<Compile Include="System\Xml\Schema\DateAndTime\Converters\DateAndTimeConverter.cs" />
<Compile Include="System\Xml\Schema\DateAndTime\Helpers\DateAndTimeInfo.cs" />
<Compile Include="System\Xml\Schema\DateAndTime\Helpers\DateInfo.cs" />
<Compile Include="System\Xml\Schema\DateAndTime\Helpers\TimeInfo.cs" />
<Compile Include="System\Xml\Schema\DateAndTime\Specifications\DateTimeTypeCode.cs" />
<Compile Include="System\Xml\Schema\DateAndTime\Specifications\XsdDateTimeKind.cs" />
<Compile Include="System\Xml\Schema\DateAndTime\XsdDate.cs" />
<Compile Include="System\Xml\Schema\DateAndTime\XsdTime.cs" />
<None Include="System\Xml\Core\HtmlEncodedRawTextWriter.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>HtmlEncodedRawTextWriter.cs</LastGenOutput>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Xml.Schema.DateAndTime.Specifications;

namespace System.Xml.Schema.DateAndTime.Helpers
{
internal struct DateAndTimeInfo
{
public DateInfo Date { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need to introduce extra data structures? The original code didn't seem to have them

public XsdDateTimeKind Kind { get; }
public TimeInfo Time { get; }
public DateTimeTypeCode TypeCode { get; }
public int ZoneHour { get; }
public int ZoneMinute { get; }

public DateAndTimeInfo(
DateInfo date,
XsdDateTimeKind kind,
TimeInfo time,
DateTimeTypeCode typeCode,
int zoneHour,
int zoneMinute)
{
Date = date;
Kind = kind;
Time = time;
TypeCode = typeCode;
ZoneHour = zoneHour;
ZoneMinute = zoneMinute;
}

public DateAndTimeInfo()
: this(
default,
XsdDateTimeKind.Unspecified,
default,
default,
0,
0)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Xml.Schema.DateAndTime.Helpers
{
internal struct DateInfo
{
public static readonly DateInfo DefaultValue = new DateInfo(FirstDay, FirstMonth, LeapYear);

public const int FirstDay = 1;
public const int FirstMonth = 1;
public const int LeapYear = 1904;

public int Day { get; }
public int Month { get; }
public int Year { get; }

public DateInfo(int day, int month, int year)
{
Day = day;
Month = month;
Year = year;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Xml.Schema.DateAndTime.Helpers
{
internal struct TimeInfo
{
public int Fraction { get; }
public int Hour { get; }
public int Microsecond
{
get
{
return Convert.ToInt32((Fraction % TimeSpan.TicksPerMillisecond) / TimeSpan.TicksPerMicrosecond);
}
}

public int Millisecond
{
get
{
return Convert.ToInt32(Fraction / TimeSpan.TicksPerMillisecond);
}
}

public int Minute { get; }
public int Second { get; }

public TimeInfo(int fraction, int hour, int minute, int second)
{
Fraction = fraction;
Hour = hour;
Minute = minute;
Second = second;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Xml.Schema.DateAndTime.Specifications
{
/// <summary>
/// Subset of represented XML Schema types.
/// </summary>
internal enum DateTimeTypeCode
{
DateTime,
Time,
Date,
GYearMonth,
GYear,
GMonthDay,
GDay,
GMonth,
XdrDateTime,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Xml.Schema.DateAndTime.Specifications
{
/// <summary>
/// Internal representation of <see cref="System.DateTimeKind"/>.
/// </summary>
internal enum XsdDateTimeKind
{
Unspecified,
Zulu,
LocalWestOfZulu, // GMT-1..14, N..Y
LocalEastOfZulu // GMT+1..14, A..M
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Xml.Schema.DateAndTime.Converters;
using System.Xml.Schema.DateAndTime.Helpers;

namespace System.Xml.Schema.DateAndTime
{
internal struct XsdDate : IFormattable
{
private DateOnly Date { get; set; }

private XsdDate(DateInfo parsedValue)
: this()
{
Date = new DateOnly(parsedValue.Year, parsedValue.Month, parsedValue.Day);
}

/// <inheritdoc/>
public string ToString(string? format, IFormatProvider? formatProvider)
{
return Date.ToString(format, formatProvider);
}

internal static bool TryParse(string text, out XsdDate result)
{
if (!DateAndTimeConverter.TryParse(text, out DateInfo parsedValue))
{
result = default;
return false;
}

result = new XsdDate(parsedValue);
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Xml.Schema.DateAndTime.Converters;
using System.Xml.Schema.DateAndTime.Helpers;

namespace System.Xml.Schema.DateAndTime
{
internal struct XsdTime : IFormattable
{
private TimeOnly Time { get; set; }

private XsdTime(TimeInfo parsedValue)
: this()
{
Time = new TimeOnly(
parsedValue.Hour,
parsedValue.Minute,
parsedValue.Second,
parsedValue.Millisecond,
parsedValue.Microsecond);
}

/// <inheritdoc/>
public string ToString(string? format, IFormatProvider? formatProvider)
{
return Time.ToString(format, formatProvider);
}

internal static bool TryParse(string text, out XsdTime result)
{
if (!DateAndTimeConverter.TryParse(text, out TimeInfo parsedValue))
{
result = default;
return false;
}

result = new XsdTime(parsedValue);
return true;
}
}
}
Loading