Converting timezones from the Xero API to Windows format (.Net)
Hi everybody. Was working on a Xero integration today and was reminded of a little gotcha when integrating data using the Xero API - timezone formatting.
You see, Xero maintains its own list of keys to indicate timezones, but these aren’t much use to use .Net developers because they don’t match the built-in identifiers in the TimeZoneInfo
class.
At first glance it seems like you may need to manually write a mapping, but look a little closer - each identifier in the Xero list is actually a stripped-down version of our Windows equivalents. Specifically, Xero has simply stripped the non-alpha characters like spaces and full-stops and then capitalized it.
So, here’s a handy little utility we use to do the conversion. This allows us to sync invoices from Xero but store the due date etc in UTC, so our integrations can continue working with it safely.
Easy huh? Hope you find it useful.