Skip to content

Conversation

@axunonb
Copy link
Collaborator

@axunonb axunonb commented Jul 4, 2025

Throws for controversion of ISO 8601 UTC string, while timezone ID is not UTC

chore: ExcludeFromCodeCoverage for private constructor
chore: Remove unused method TruncateTimeToSeconds

Resolves #831

@codecov
Copy link

codecov bot commented Jul 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

❌ Your project status has failed because the head coverage (68%) is below the target coverage (80%). You can increase the head coverage or adjust the target coverage.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #833   +/-   ##
===================================
  Coverage    68%    68%           
===================================
  Files       106    106           
  Lines      4217   4214    -3     
  Branches    942    943    +1     
===================================
+ Hits       2850   2851    +1     
+ Misses     1039   1035    -4     
  Partials    328    328           
Files with missing lines Coverage Δ
Ical.Net/DataTypes/CalDateTime.cs 90% <100%> (+2%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@axunonb axunonb requested a review from NRG-Drink July 4, 2025 12:31
@axunonb axunonb marked this pull request as ready for review July 4, 2025 12:31
@axunonb axunonb force-pushed the wip/axunonb/pr/fix-caldatetime-ctor branch 2 times, most recently from c96911f to 44cb30f Compare July 4, 2025 12:52
Comment on lines 205 to 209
CopyFrom(serializer.Deserialize(new StringReader(value)) as CalDateTime
?? throw new InvalidOperationException($"$Failure for deserializing value '{value}'"));
?? throw new InvalidOperationException($"$Failure when deserializing value '{value}'"));

// The string may contain a date only, meaning that the tzId should be ignored.
_tzId = HasTime ? tzId : null;
_tzId ??= HasTime ? tzId : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

CopyFrom is used only once and it will set _tzId regardless of the time.
I suggest to delete CopyFrom and use Initialize.

Suggested change
CopyFrom(serializer.Deserialize(new StringReader(value)) as CalDateTime
?? throw new InvalidOperationException($"$Failure for deserializing value '{value}'"));
?? throw new InvalidOperationException($"$Failure when deserializing value '{value}'"));
// The string may contain a date only, meaning that the tzId should be ignored.
_tzId = HasTime ? tzId : null;
_tzId ??= HasTime ? tzId : null;
var dt = serializer.Deserialize(new StringReader(value)) as CalDateTime
?? throw new InvalidOperationException($"$Failure when deserializing value '{value}'");
Initialize(dt._dateOnly, dt._timeOnly, dt._tzId);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, CopyFrom is redundant.
Initializing should read

Initialize(dt._dateOnly, dt._timeOnly, dt.IsUtc ? UtcTzId : tzId);

to reflect that UTC may be set from the deserialized string (appended 'Z') or from the tzId argument. This correction is actually the aim of the PR.

Throws for controversion of ISO 8601 UTC string, while timezone ID is not UTC

chore: `ExcludeFromCodeCoverage` for private constructor
chore: Remove unused method `TruncateTimeToSeconds`

Resolves #831
@axunonb axunonb force-pushed the wip/axunonb/pr/fix-caldatetime-ctor branch from 44cb30f to 32ca1c9 Compare July 5, 2025 10:41
* Updated the `CalDateTime(string value, string? tzId = null)` constructor to directly initialize the object using the `Initialize` method.
* Removed the unnecessary `CopyFrom` method.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 5, 2025

@axunonb axunonb merged commit 4b8d45a into main Jul 5, 2025
8 of 9 checks passed
@axunonb axunonb deleted the wip/axunonb/pr/fix-caldatetime-ctor branch July 5, 2025 10:48
@axunonb
Copy link
Collaborator Author

axunonb commented Jul 5, 2025

@NRG-Drink Thanks for the helpful review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CalDateTime constructor doesn't properly parse Z time

3 participants