Firstly, I'd recommend that if you use Noda Time, you use it as widely as possible rather than in small pockets like this. The less code you have using the BCL types (DateTime
etc) the better.
The problem here isn't caused by Noda Time though - it's caused by the conversion from DateTime
to DateTimeOffset
.
The code you've got converts a LocalDateTime
to a DateTime
with a Kind
of Unspecified
. As noted in comments, you're actually using DateTimeOffset
in your code. The implicit conversion from DateTime
to DateTimeOffset
will perform a time zone conversion using the default system time zone when the Kind
is either Unspecified
or Local
. (This sort of implicit use of ambient context is one of the things Noda Time tries to prevent.) It sounds like your Linux server has one system time zone, and the Windows server has a different one.
If you want to keep the DateTimeOffset
part of your code, but accurately represent an instant in a particular time zone, the simplest fix is to change the methods to return DateTimeOffset
, and just call ZonedDateTime.ToDateTimeOffset
at the end of ConvertToLocalTime
:
return new ZonedDateTime(instant, timeZone).ToDateTimeOffset();