/// <summary> /// This is a recursive method to replace C# date format strings into jquery strings /// </summary> /// <param name="repStr"></param> /// <param name="rep"></param> /// <param name="dict"></param> /// <returns></returns> public static string FormatConvert(string repStr, int rep, string[,] dict) { if (dict.GetLength(0) > (rep)) { string[] repKey = new string[] { dict[rep, 0] }; string repVal = dict[rep, 1]; if (repStr.Length > 0) { string[] repArr = repStr.Split(repKey, StringSplitOptions.None); string val = ""; for (var item = 0; item < repArr.Length - 1; item++) { if (dict.GetLength(0) > (rep)) { val = val + BuilderUtility.FormatConvert(repArr[item], rep + 1, dict); } val = val + repVal; } return(val + BuilderUtility.FormatConvert(repArr[repArr.Length - 1], rep + 1, dict)); } else { return(""); } } else { string val = repStr; return(val); } }
/// <summary> /// This method converts C# dateformat style into jqueryui dateformat /// </summary> /// <param name="inputFormat">Input dateformat as string</param> /// <returns>Converted dateformat as string</returns> public static string DateFormatConversion(string inputFormat) { string outputFormat = null; if (inputFormat != null) { if (inputFormat.Length == 1) { switch (inputFormat) { case "d": outputFormat = "mm/dd/yy"; break; case "D": outputFormat = "DD, dd MM yy"; break; case "f": outputFormat = "DD, dd MM yy"; break; case "F": outputFormat = "DD, dd MM yy"; break; case "g": outputFormat = "mm/dd/yy"; break; case "G": outputFormat = "mm/dd/yy"; break; case "m": outputFormat = "M-d"; break; case "M": outputFormat = "M-d"; break; case "o": outputFormat = "yy-mm-dd"; break; case "O": outputFormat = "yy-mm-dd"; break; case "r": outputFormat = "D, dd M yy"; break; case "R": outputFormat = "D, dd M yy"; break; case "s": outputFormat = "yy-mm-dd"; break; case "u": outputFormat = "yy-mm-dd"; break; case "U": outputFormat = "DD, dd MM yy"; break; case "y": outputFormat = "yy MM"; break; case "Y": outputFormat = "yy MM"; break; default: outputFormat = "mm/dd/yy"; break; } } else { string[,] replacementList = new string[, ] { { "dddd", "DD" } , { "ddd", "D" } , { "MMMM", "MM" } , { "MMM", "M" } , { "MM", "mm" } , { "M", "m" } , { "yyyy", "yy" } , { "yyy", "yy" } , { "yy", "y" } , { "g", "" } , { "t", "" } , { "s", "" } , { "f", "" } , { "h", "" } , { "m", "" } , { "z", "" } , { "F", "" } , { "H", "" } , { "K", "" } }; outputFormat = BuilderUtility.FormatConvert(inputFormat, 0, replacementList); } } return(outputFormat); }