Skip to content
Merged
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
13 changes: 4 additions & 9 deletions src/Polyfill/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,21 @@ static partial class Polyfill

extension(DateTimeOffset target)
{
// The offset is a whole number of minutes, so the UTC ticks have the same sub-second part as the clock time

/// <summary>
/// Gets the nanosecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.nanosecond?view=net-11.0
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.UtcTicks % TicksPerMicrosecond) * 100;

/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.microsecond?view=net-11.0
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);

long TicksComponent()
{
var noSeconds = new DateTimeOffset(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Offset);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.UtcTicks / TicksPerMicrosecond % 1000);
}

#endif
Expand Down
11 changes: 2 additions & 9 deletions src/Polyfill/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ static partial class Polyfill
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.nanosecond?view=net-11.0
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;

/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.microsecond?view=net-11.0
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);

long TicksComponent()
{
var noSeconds = new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Kind);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}

#endif
Expand Down
11 changes: 2 additions & 9 deletions src/Polyfill/TimeSpanPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ static partial class Polyfill
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.timespan.nanoseconds?view=net-11.0
public int Nanoseconds =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;

/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.timespan.microseconds?view=net-11.0
public int Microseconds =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);

long TicksComponent()
{
var noSeconds = new TimeSpan(target.Days, target.Hours, target.Minutes, 0);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
#endif

Expand Down
10 changes: 2 additions & 8 deletions src/Split/net461/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.UtcTicks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTimeOffset(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Offset);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.UtcTicks / TicksPerMicrosecond % 1000);
}
extension(DateTimeOffset)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net461/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Kind);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
extension(DateTime)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net461/TimeSpanPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Nanoseconds =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Microseconds =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new TimeSpan(target.Days, target.Hours, target.Minutes, 0);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
const long MicrosecondsToTicks = TimeSpan.TicksPerMillisecond / 1000;
const long MicrosecondsPerMillisecond = 1_000;
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net462/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.UtcTicks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTimeOffset(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Offset);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.UtcTicks / TicksPerMicrosecond % 1000);
}
extension(DateTimeOffset)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net462/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Kind);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
extension(DateTime)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net462/TimeSpanPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Nanoseconds =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Microseconds =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new TimeSpan(target.Days, target.Hours, target.Minutes, 0);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
const long MicrosecondsToTicks = TimeSpan.TicksPerMillisecond / 1000;
const long MicrosecondsPerMillisecond = 1_000;
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net47/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.UtcTicks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTimeOffset(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Offset);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.UtcTicks / TicksPerMicrosecond % 1000);
}
extension(DateTimeOffset)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net47/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Kind);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
extension(DateTime)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net47/TimeSpanPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Nanoseconds =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Microseconds =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new TimeSpan(target.Days, target.Hours, target.Minutes, 0);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
const long MicrosecondsToTicks = TimeSpan.TicksPerMillisecond / 1000;
const long MicrosecondsPerMillisecond = 1_000;
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net471/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.UtcTicks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTimeOffset(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Offset);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.UtcTicks / TicksPerMicrosecond % 1000);
}
extension(DateTimeOffset)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net471/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Kind);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
extension(DateTime)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net471/TimeSpanPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Nanoseconds =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Microseconds =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new TimeSpan(target.Days, target.Hours, target.Minutes, 0);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
const long MicrosecondsToTicks = TimeSpan.TicksPerMillisecond / 1000;
const long MicrosecondsPerMillisecond = 1_000;
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net472/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.UtcTicks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTimeOffset"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTimeOffset(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Offset);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.UtcTicks / TicksPerMicrosecond % 1000);
}
extension(DateTimeOffset)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net472/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Nanosecond =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="DateTime"/> object.
/// </summary>
public int Microsecond =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new DateTime(target.Year, target.Month, target.Day, target.Hour, target.Minute, 0, target.Kind);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
extension(DateTime)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Split/net472/TimeSpanPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ static partial class Polyfill
/// Gets the nanosecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Nanoseconds =>
(int) (target.TicksComponent() % TicksPerMicrosecond) * 100;
(int) (target.Ticks % TicksPerMicrosecond) * 100;
/// <summary>
/// Gets the microsecond component of the time represented by the current <see cref="TimeSpan"/> object.
/// </summary>
public int Microseconds =>
(int) (target.TicksComponent() / TicksPerMicrosecond % 1000);
long TicksComponent()
{
var noSeconds = new TimeSpan(target.Days, target.Hours, target.Minutes, 0);
var secondsPart = target - noSeconds;
return secondsPart.Ticks;
}
(int) (target.Ticks / TicksPerMicrosecond % 1000);
}
const long MicrosecondsToTicks = TimeSpan.TicksPerMillisecond / 1000;
const long MicrosecondsPerMillisecond = 1_000;
Expand Down
Loading
Loading