From db421dc25e9f05f48f737de9e2aff96d315e0748 Mon Sep 17 00:00:00 2001 From: bhudgins <35714322+bhudgins@users.noreply.github.com> Date: Sat, 6 Feb 2021 19:32:10 -0600 Subject: [PATCH] created functions --- App/Program.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/App/Program.cs b/App/Program.cs index c4c26a8..fbdfb6c 100644 --- a/App/Program.cs +++ b/App/Program.cs @@ -1,8 +1,11 @@ using System; +using System.Globalization; +using System.Text.RegularExpressions; + namespace App { - public class Program + public static class Program { static void Main(string[] args) { @@ -11,12 +14,54 @@ static void Main(string[] args) public static string ConvertToTitleCase(string inpStr) { - return inpStr; + + if(inpStr != null) { + Regex rgx = new Regex("[^a-zA-Z0-9 ]"); + inpStr = rgx.Replace(inpStr, " "); //Find and replace all non-alphanumeric characters with spaces + inpStr = inpStr.Trim(); //Remove excess left on str + inpStr = inpStr.ToLower(); //Change entire string to lower case - easier to do that + // and convert first letter of each word to capital letter rather than find and replace each capital with a lower case. + + inpStr = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(inpStr.ToLower()); + return inpStr; + } + else{ + throw new ArgumentException("Parameter cannot be null", nameof(inpStr)); + + } + + } + + public static string ConvertUnixToDateString(long? inpUnixSeconds) { - return inpUnixSeconds.ToString(); + String monthDay = ""; + String year = ""; + + if(inpUnixSeconds.HasValue){ + long inpUnixSeconds2 = inpUnixSeconds.GetValueOrDefault(); + DateTime dateTime = (DateTimeOffset.FromUnixTimeSeconds(inpUnixSeconds2)).DateTime; + monthDay = dateTime.ToString("MMMM d"); + year = dateTime.ToString("yyyy"); + + + // let month = dateObj.toLocaleString('default', { month: 'long' }); + // let day = dateObj.getDate(); + // let year = dateObj.getFullYear(); + // dateStr = month + " " + day + ", " + year; + } + else if(inpUnixSeconds == null){ + throw new Exception(); + } + else if(!inpUnixSeconds.HasValue){ + monthDay = DateTime.Now.ToString("MMMM d"); + year = DateTime.Now.ToString("yyyy"); + } + + return monthDay + ", " + year; + } } } \ No newline at end of file