Skip to content

Commit e854bd8

Browse files
DharmishthaVPatelDharmishtha Patel
andauthored
Fix Timestamp format block in headers based on version and Remove timestamp conversion snippet (#7218)
Co-authored-by: Dharmishtha Patel <dharmishthapatel@Dharmishthas-MacBook-Pro.local>
1 parent 82c958c commit e854bd8

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

nservicebus/messaging/headers.md

Lines changed: 6 additions & 19 deletions
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,)
2021
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(DateTimeOffset)` and `ToDateTimeOffset(string)` methods.
22+
#end-if
23+
24+
#if-version [,8)
25+
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(DateTime)` and `ToUtcDateTime(string)` methods.
26+
#end-if
2127

2228
### ISO 8601 format
2329

@@ -29,32 +35,13 @@ Differences:
2935
2. uses a `.` between seconds and milli/microseconds
3036
3. no space between the timestamp and the `Z`
3137

32-
3338
```
3439
ISO 8601: yyyy-MM-ddTHH:mm:ss.ffffffZ
3540
NServiceBus: yyyy-MM-dd HH:mm:ss:ffffff Z
3641
```
3742

3843
When doing native intergration and there is a need to parse the timestamp the `.` as second and milli/microsecond separator is where regular timestamp parsers often fail.
3944

40-
Use the following code to generate or read the NServiceBus custom timestamp format.
41-
42-
```cs
43-
const string Format = "yyyy-MM-dd HH:mm:ss:ffffff Z"; // Not ISO 8601
44-
45-
public static string ToWireFormattedString(DateTime dateTime)
46-
{
47-
return dateTime.ToUniversalTime()
48-
.ToString(Format, CultureInfo.InvariantCulture);
49-
}
50-
51-
public static DateTime ToUtcDateTime(string wireFormattedString)
52-
{
53-
return DateTime.ParseExact(wireFormattedString, Format, CultureInfo.InvariantCulture)
54-
.ToUniversalTime();
55-
}
56-
```
57-
5845
## Transport headers
5946

6047
### NServiceBus.NonDurableMessage

0 commit comments

Comments
 (0)