Created
December 30, 2018 12:08
-
-
Save justinyoo/f98f86536560c9b99cedbdcf48cadb4c to your computer and use it in GitHub Desktop.
Locale Settings in Azure Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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