joshb
joshb

Reputation: 5220

Convert DateTime field token to local time zone in email rule

Within Orchard I have a custom content type that includes a DateTime field. I've created a rule to send an email when a new content item is submitted. I'm able to include the value of the DateTime field in the email using the following token:

{Content.Fields.MyContentType.MyDateTimeField}

The problem I'm running into is that the date/time value that replaces the token is in UTC and I need it to be in the timezone configured for my Orchard instance.

I see there's a token for the current date/time that looks like this:

{Date.Local}

But .Local does not seem to be valid on the DateTime field token.

It looks like it wouldn't be too hard to create a custom token provider to solve for this but before I did that I wanted to make sure I wasn't missing an easier, existing solution.

Upvotes: 2

Views: 1228

Answers (1)

Bertrand Le Roy
Bertrand Le Roy

Reputation: 17814

The date token does indeed have a Local subtoken but the problem here is that {Content.Fields.MyContentType.MyDateTimeField} is not a date token, it's still just the field. You need to get its actual value. If you look at FieldTokens.cs, you'll see that the date field token has a DateTime token. So {Content.Fields.MyContentType.MyDateTimeField.DateTime.Local} should do the trick I think.

Upvotes: 3

Related Questions