Skip to content

Implement Serialize/Deserialize for DATE, TIME, and DATETIME#159

Open
imurasawa wants to merge 4 commits into
ela-compil:masterfrom
imurasawa:fix/datetime-serialize
Open

Implement Serialize/Deserialize for DATE, TIME, and DATETIME#159
imurasawa wants to merge 4 commits into
ela-compil:masterfrom
imurasawa:fix/datetime-serialize

Conversation

@imurasawa

Copy link
Copy Markdown

Implement Serialize/Deserialize for DATE, TIME, and DATETIME

Problem

Current state of SerializeValue / DeserializeValue in Property.cs:

Type Serialize (write) Deserialize (read)
DATE Falls through to default: ToString() — works DateTime.Parse() — works
TIME Falls through to default: ToString() — hundredths lost DateTime.Parse() — works, but hundredths already lost
DATETIME Falls through to default: ToString() — writes something, but… No case → default: null → read returns null

Fix

Added explicit cases for DATE, TIME, and DATETIME in both SerializeValue and DeserializeValue, using the same ASCII format as bacnet-stack's datetime_to_ascii():

Type Format
DATE yyyy/MM/dd
TIME HH:mm:ss.hh (hh = hundredths, 0–99)
DATETIME yyyy/MM/dd-HH:mm:ss.hh

Note: C#'s DateTime does not have a hundredths field, so the conversion uses Millisecond / 10.

Verification

Read OBJECT_DATETIME_VALUE from a separate Linux machine (Raspberry Pi 4) using bacnet-stack's bacrp:

BACNET_IFACE=eth0 ./bacrp 22 44 1000 85
→ {Wednesday, May 27, 2026-17:47:33.95}

The value was correctly decoded on the bacnet-stack side.

Note: the display format produced by bacrp differs from yyyy/MM/dd-HH:mm:ss.hh; this is due to bacrp's own display formatting, not the wire encoding.

Notes

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.

1 participant