Skip to content

Make API .NET-first: DateTimeOffset for timestamps/dates, bool for string-encoded booleans#13

Merged
Shane32 merged 5 commits intomasterfrom
copilot/change-date-fields-to-datetimeoffset
Mar 31, 2026
Merged

Make API .NET-first: DateTimeOffset for timestamps/dates, bool for string-encoded booleans#13
Shane32 merged 5 commits intomasterfrom
copilot/change-date-fields-to-datetimeoffset

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

All date, timestamp, and boolean fields in the API models used raw primitive types (long, string, bool?) mirroring the JSON wire format. This converts them to proper .NET types with bidirectional JSON conversion handled via [JsonConverter] attributes on the model properties.

New JSON Converters (Project/JsonConverters/)

Converter Wire format .NET type
UnixTimestampConverter / NullableUnixTimestampConverter long (Unix seconds) DateTimeOffset / DateTimeOffset?
DateTimeOffsetDateConverter / NullableDateTimeOffsetDateConverter "YYYY-MM-DD" string DateTimeOffset? (midnight UTC)
EnabledDisabledConverter "enabled" / "disabled" bool?
StringBoolConverter "true" / "false" bool?

All converters throw JsonException on unrecognized values.

Model field changes

  • All long? unix timestamp fields → DateTimeOffset?
  • All string? ISO date fields → DateTimeOffset?
  • ChargingSession.StartTime / EndTime (non-nullable) → DateTimeOffset
  • ChargingSession.Duration / ChargeTime preserved as long — these are durations in seconds, not timestamps
  • BatterySettings.ChargeFromGrid, EnergyIndependencebool?
  • StormGuardSettings.StormGuardStatusbool? (via EnabledDisabledConverter)
  • StormGuardSettings.StormAlertbool? (via StringBoolConverter, API returns "false" string)
  • UpdateBatterySettingsRequest.EnergyIndependencebool? (serializes back as "enabled"/"disabled")

Client method signature changes

All long/long? timestamp parameters and string/string? date parameters replaced with DateTimeOffset/DateTimeOffset?. Conversion is done internally in EnphaseClient:

// Before
GetSystemEventsAsync(int systemId, long startTime, long? endTime = null)
GetEnergyLifetimeAsync(int systemId, string? startDate = null, string? endDate = null, ...)

// After
GetSystemEventsAsync(int systemId, DateTimeOffset startTime, DateTimeOffset? endTime = null)
GetEnergyLifetimeAsync(int systemId, DateTimeOffset? startDate = null, DateTimeOffset? endDate = null, ...)

Internally, timestamp params use .ToUnixTimeSeconds() and date params use .ToString("yyyy-MM-dd") when building query strings.

Copilot AI and others added 2 commits March 31, 2026 14:35
…booleans to bool?

- Add JSON converter files for Unix timestamps, ISO dates, enabled/disabled strings, and true/false strings
- Convert all Unix timestamp fields (long/long?) to DateTimeOffset/DateTimeOffset? with NullableUnixTimestampConverter
- Convert all ISO date string fields (string?) to DateTimeOffset? with NullableDateTimeOffsetDateConverter
- Convert enabled/disabled string fields to bool? with EnabledDisabledConverter
- Convert true/false string bool fields to bool? with StringBoolConverter
- Update ChargingSession start_time/end_time (non-nullable) to DateTimeOffset with UnixTimestampConverter
- Preserve ChargingSession.Duration and ChargeTime as long (duration in seconds, not timestamps)
- Update all IEnphaseClient and EnphaseClient method signatures to use DateTimeOffset instead of long/string for timestamps/dates
- Update EnphaseClient to serialize DateTimeOffset params correctly (ToUnixTimeSeconds for timestamps, yyyy-MM-dd for dates)
- Update tests to use DateTimeOffset values and fix assertions for bool? fields
- Update approved API snapshot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Shane32 <6377684+Shane32@users.noreply.github.com>
Copilot AI changed the title [WIP] Update API to use DateTimeOffset for date fields Make API .NET-first: DateTimeOffset for timestamps/dates, bool for string-encoded booleans Mar 31, 2026
Copilot AI requested a review from Shane32 March 31, 2026 14:46
@Shane32 Shane32 marked this pull request as ready for review March 31, 2026 14:55
@Shane32 Shane32 merged commit a7531fe into master Mar 31, 2026
4 checks passed
@Shane32 Shane32 deleted the copilot/change-date-fields-to-datetimeoffset branch March 31, 2026 14:57
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.

2 participants