Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created December 30, 2018 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/f98f86536560c9b99cedbdcf48cadb4c to your computer and use it in GitHub Desktop.
Save justinyoo/f98f86536560c9b99cedbdcf48cadb4c to your computer and use it in GitHub Desktop.
Locale Settings in Azure Functions
[FunctionName(nameof(Default))]
public static async Task<IActionResult> Default(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "locale/default")] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var body = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(body);
var date = (string)data.date;
var converted = DateTimeOffset.TryParse(date, out DateTimeOffset result)
? result
: DateTimeOffset.MinValue;
return (ActionResult)new OkObjectResult($"Input: {converted:O}");
}
[FunctionName(nameof(EnAu))]
public static async Task<IActionResult> EnAu(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "locale/en-au")] HttpRequest req,
ILogger log)
{
// Change the culuture of the thread currently running
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-AU");
log.LogInformation("C# HTTP trigger function processed a request.");
var body = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(body);
var date = (string)data.date;
var converted = DateTimeOffset.TryParse(date, out DateTimeOffset result)
? result
: DateTimeOffset.MinValue;
return (ActionResult)new OkObjectResult($"Input: {converted:O}");
}
[FunctionName(nameof(KoKr))]
public static async Task<IActionResult> KoKr(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "locale/ko-kr")] HttpRequest req,
ILogger log)
{
// Change the culuture of the thread currently running
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ko-KR");
log.LogInformation("C# HTTP trigger function processed a request.");
var body = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(body);
var date = (string)data.date;
var converted = DateTimeOffset.TryParse(date, out DateTimeOffset result)
? result
: DateTimeOffset.MinValue;
return (ActionResult)new OkObjectResult($"Input: {converted:O}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment