Skip to content

Commit 8acfcaf

Browse files
DharmishthaVPatelDharmishtha Patel
andauthored
Add partial Markdown for handling Timestamp block based on version (#7214)
Co-authored-by: Dharmishtha Patel <[email protected]>
1 parent 4c18b98 commit 8acfcaf

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

nservicebus/messaging/headers.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ The headers of a message are similar to HTTP headers and contain metadata about
1717

1818
## Timestamp format
1919

20+
#if-version [8,)
21+
For all timestamp message headers, the format is `yyyy-MM-dd HH:mm:ss:ffffff Z` where the time is UTC. The helper class `DateTimeOffsetHelper` supports converting from UTC to wire format and vice versa by using the `ToWireFormattedString()` and `ToDateTimeOffset()` methods.
22+
#end-if
23+
24+
#if-version [,8)
2025
For all timestamp message headers, the format is `yyyy-MM-dd HH:mm:ss:ffffff Z` where the time is UTC. The helper class `DateTimeExtensions` supports converting from UTC to wire format and vice versa by using the `ToWireFormattedString()` and `ToUtcDateTime()` methods.
26+
#end-if
2127

2228
### ISO 8601 format
2329

@@ -42,17 +48,30 @@ Use the following code to generate or read the NServiceBus custom timestamp form
4248
```cs
4349
const string Format = "yyyy-MM-dd HH:mm:ss:ffffff Z"; // Not ISO 8601
4450
51+
#if-version [8,)
52+
public static string ToWireFormattedString(DateTimeOffset dateTime)
53+
{
54+
return dateTime.ToUniversalTime().ToString(format, CultureInfo.InvariantCulture);
55+
}
56+
public static DateTimeOffset ToUtcDateTime(string wireFormattedString)
57+
{
58+
return DateTimeOffset.ParseExact(wireFormattedString, Format, CultureInfo.InvariantCulture)
59+
.ToUniversalTime();
60+
}
61+
#end-if
62+
63+
#if-version [,8)
4564
public static string ToWireFormattedString(DateTime dateTime)
4665
{
4766
return dateTime.ToUniversalTime()
4867
.ToString(Format, CultureInfo.InvariantCulture);
4968
}
50-
5169
public static DateTime ToUtcDateTime(string wireFormattedString)
5270
{
5371
return DateTime.ParseExact(wireFormattedString, Format, CultureInfo.InvariantCulture)
5472
.ToUniversalTime();
5573
}
74+
#end-if
5675
```
5776

5877
## Transport headers

0 commit comments

Comments
 (0)