Title: Feature Request: ASCWriter should support configurable timestamp format (absolute vs relative) · Issue #2022 · hardbyte/python-can · GitHub
Open Graph Title: Feature Request: ASCWriter should support configurable timestamp format (absolute vs relative) · Issue #2022 · hardbyte/python-can
X Title: Feature Request: ASCWriter should support configurable timestamp format (absolute vs relative) · Issue #2022 · hardbyte/python-can
Description: Problem Description ASCWriter currently has the following issues: Header declaration doesn't match actual content: ASCWriter declares "base hex timestamps absolute" in the file header But actually writes relative timestamps (starting fro...
Open Graph Description: Problem Description ASCWriter currently has the following issues: Header declaration doesn't match actual content: ASCWriter declares "base hex timestamps absolute" in the file header But actually ...
X Description: Problem Description ASCWriter currently has the following issues: Header declaration doesn't match actual content: ASCWriter declares "base hex timestamps absolute" in the file header...
Opengraph URL: https://github.com/hardbyte/python-can/issues/2022
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Request: ASCWriter should support configurable timestamp format (absolute vs relative)","articleBody":"\n\n## Problem Description\n\nASCWriter currently has the following issues:\n\n1. **Header declaration doesn't match actual content**:\n - ASCWriter declares `\"base hex timestamps absolute\"` in the file header\n - But actually writes relative timestamps (starting from 0)\n\n2. **Lack of flexibility**:\n - No parameter to control timestamp format\n - Users cannot choose between absolute or relative timestamp formats\n\n3. **Inconsistent with ASCReader**:\n - ASCReader supports `relative_timestamp` parameter to control timestamp format\n - ASCWriter lacks corresponding parameter, causing inconsistent data processing workflow\n\n## Current Behavior Example\n\n```python\n# Original ASC file may contain absolute timestamps\n# 445678.123456 1 123 Tx d 8 00 00 00 00 00 00 00 00\n\n# Reading\nreader = ASCReader('input.asc', relative_timestamp=True) # Can control format\nmessages = list(reader)\n\n# Writing\nwriter = ASCWriter('output.asc') # Cannot control format\nfor msg in messages:\n writer.on_message_received(msg)\nwriter.stop()\n\n# Output file\n# Header: base hex timestamps absolute \n# Actual content: 0.123456 1 123 Tx d 8 00 00 00 00 00 00 00 00\n```\n\n\n## Expected Behavior\n\nAdd a parameter to let ASCWriter support configurable timestamp format:\n\n```python\n# Option 1: Keep relative timestamps (default behavior, backward compatible)\nwriter = ASCWriter('output.asc', absolute_timestamps=False) # Default value\n\n# Option 2: Use absolute timestamps \nwriter = ASCWriter('output.asc', absolute_timestamps=True) # New feature\n```\n\n\n## Implementation Suggestion\n\nModify ASCWriter's constructor and timestamp processing logic:\n\n```python\nclass ASCWriter(TextIOMessageWriter):\n def __init__(\n self,\n file: Union[StringPathLike, TextIO],\n channel: int = 1,\n absolute_timestamps: bool = False, # New parameter\n **kwargs: Any,\n ) -\u003e None:\n \"\"\"\n :param file: a path-like object or as file-like object to write to\n If this is a file-like object, is has to opened in text\n write mode, not binary write mode.\n :param channel: a default channel to use when the message does not\n have a channel set\n :param absolute_timestamps: whether to use absolute timestamps or relative \n timestamps starting from 0 (default: False)\n \"\"\"\n # ... existing code ...\n \n self.absolute_timestamps = absolute_timestamps\n # Set correct header based on parameter\n timestamp_format = \"absolute\" if absolute_timestamps else \"relative\"\n self.file.write(f\"base hex timestamps {timestamp_format}\\n\")\n # ... rest of existing code ...\n\n def log_event(self, message: str, timestamp: Optional[float] = None) -\u003e None:\n # ... existing code ...\n \n # Decide whether to convert to relative timestamp based on configuration\n if not self.absolute_timestamps and timestamp \u003e= self.started:\n timestamp -= self.started\n line = self.FORMAT_EVENT.format(timestamp=timestamp, message=message)\n self.file.write(line)\n```\n\n\n## Compatibility Considerations\n\n- Default value `absolute_timestamps=False` maintains backward compatibility\n- Existing code remains unaffected\n- File header matches actual content\n\n## Additional Context\n\n- **python-can version**: 4.3.1+ (or latest version)\n- **Python version**: 3.x\n- **Operating System**: All platforms\n\nThis issue affects users who need to preserve original timestamp format, especially in data processing and analysis scenarios where absolute timestamps are important for time synchronization with other data sources.\n\nThe inconsistency between ASCReader (which supports configurable timestamp format) and ASCWriter (which doesn't) creates confusion and limits the library's usability for certain use cases.\n","author":{"url":"https://github.com/dev4ray","@type":"Person","name":"dev4ray"},"datePublished":"2026-01-18T15:39:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2022/python-can/issues/2022"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:36c63973-76f6-4c2e-e4dc-090f7b316df6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 86FC:116E4B:3C5F1E3:4F077C0:6A5D1751 |
| html-safe-nonce | 81ec547e6f0945ccf9bcafd250c7018912d9457f1d834bd25e2561637b4fb779 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkZDOjExNkU0QjozQzVGMUUzOjRGMDc3QzA6NkE1RDE3NTEiLCJ2aXNpdG9yX2lkIjoiODkyMjMyNjgxMTUxNjE0NzUzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2a385abd8c45d2b756b29caaf8ce499746f8467068d3b278d8e2be1a958515df |
| hovercard-subject-tag | issue:3826926262 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/hardbyte/python-can/2022/issue_layout |
| twitter:image | https://opengraph.githubassets.com/703de8c3b275e0726ffb03e370cef02e6683eddc7d2ba5332cdda5f7efbdb8a7/hardbyte/python-can/issues/2022 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/703de8c3b275e0726ffb03e370cef02e6683eddc7d2ba5332cdda5f7efbdb8a7/hardbyte/python-can/issues/2022 |
| og:image:alt | Problem Description ASCWriter currently has the following issues: Header declaration doesn't match actual content: ASCWriter declares "base hex timestamps absolute" in the file header But actually ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dev4ray |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/hardbyte/python-can git https://github.com/hardbyte/python-can.git |
| octolytics-dimension-user_id | 855189 |
| octolytics-dimension-user_login | hardbyte |
| octolytics-dimension-repository_id | 69090889 |
| octolytics-dimension-repository_nwo | hardbyte/python-can |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 69090889 |
| octolytics-dimension-repository_network_root_nwo | hardbyte/python-can |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width