Parse date/time in a locale independent manner

Creates a new threadsafe context manager to temporarily reset locale so that
strptime behaves as desired. Fixes #2271.

@jamesls please review.