public void TimeModifiers_Split_Secs_Zero_Expected_No_Change() { string result; string error; string inputString = "2025/02/15 11:21:51 AM"; string formatString = "yyyy/mm/dd 12h:min:ss am/pm"; IDateTimeFormatter formatter = DateTimeConverterFactory.CreateFormatter(); IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "Split Secs", 0, ""); formatter.TryFormat(dateTimeResult, out result, out error); Assert.IsTrue(result == "2025/02/15 11:21:51 AM"); }
public void TryFormat_Converting_Date_To_ww_Expected_WeekReturnedInDoubleDigitFormat() { string result; string error; string inputString = "06-01-2013"; string formatString = "dd-mm-yyyy"; IDateTimeFormatter formatter = DateTimeConverterFactory.CreateFormatter(); IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "ww", "", 0, ""); formatter.TryFormat(dateTimeResult, out result, out error); Assert.IsTrue(result == "02"); }
public void TimeModifiers_Seconds_Negative_Expected_Correct_Subtraction() { string result; string error; string inputString = "2025/02/15 11:21:51 AM"; string formatString = "yyyy/mm/dd 12h:min:ss am/pm"; IDateTimeFormatter formatter = DateTimeConverterFactory.CreateFormatter(); IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "Seconds", -2, ""); formatter.TryFormat(dateTimeResult, out result, out error); Assert.IsTrue(result == "2025/02/15 11:21:49 AM"); }
public void TimeModifiers_Days_Positive_Expected_Correct_Addition() { string result; string error; string inputString = "2025/06/15 11:21:51 AM"; string formatString = "yyyy/mm/dd 12h:min:ss am/pm"; IDateTimeFormatter formatter = DateTimeConverterFactory.CreateFormatter(); IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "Days", 30, ""); formatter.TryFormat(dateTimeResult, out result, out error); Assert.IsTrue(result == "2025/07/15 11:21:51 AM"); }
public void TimeModifiers_Years_Positive_Expected_Correct_Addition() { string result; string error; const string inputString = "2012/02/15 11:21:51 AM"; const string formatString = "yyyy/mm/dd 12h:min:ss am/pm"; IDateTimeFormatter dateTimeFormatter = DateTimeConverterFactory.CreateFormatter(); IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "Years", 25, ""); dateTimeFormatter.TryFormat(dateTimeResult, out result, out error); Assert.IsTrue(result == "2037/02/15 11:21:51 AM"); }
public void TimeModifiers_Blank_Negative_Expected_No_Change() { string result; string error; const string inputString = "2025/02/15 11:21:51 AM"; const string formatString = "yyyy/mm/dd 12h:min:ss am/pm"; IDateTimeFormatter dateTimeFormatter = DateTimeConverterFactory.CreateFormatter(); IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "", -25, ""); dateTimeFormatter.TryFormat(dateTimeResult, out result, out error); Assert.IsTrue(result == "2025/02/15 11:21:51 AM"); }
public void TryFormat_Converting_Date_To_Week_Expected_WeekofTheSpecifiedDataReturned() { string result; string error; const string inputString = "06-01-2013"; const string formatString = "dd-mm-yyyy"; IDateTimeFormatter dateTimeFormatter = DateTimeConverterFactory.CreateFormatter(); IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "w", "", 0, ""); dateTimeFormatter.TryFormat(dateTimeResult, out result, out error); Assert.IsTrue(result == "2"); }
public void FormatAllArgsValid_Expected_ResultFormattedAccordingToOutputFormat() { string result; string errorMsg; IDateTimeOperationTO dateTimeTO = new DateTimeOperationTO(); dateTimeTO.DateTime = "14101988"; dateTimeTO.InputFormat = "ddmmyyyy"; dateTimeTO.OutputFormat = @"yyyy'/'mm'/'dd"; dateTimeTO.TimeModifierType = "Years"; dateTimeTO.TimeModifierAmount = 23; formatter.TryFormat(dateTimeTO, out result, out errorMsg); string expected = "2011/10/14"; Assert.AreEqual(expected, result); }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); ErrorResultTO allErrors = new ErrorResultTO(); InitializeDebug(dataObject); // Process if no errors try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(DateTime)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time", "Input"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(System.DateTime.Now.ToString(CultureInfo.CurrentCulture), "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugEvalResult(DateTime, "Input", dataObject.Environment)); } var cultureType = typeof(CultureInfo); var fieldInfo = cultureType.GetField("s_userDefaultCulture", BindingFlags.NonPublic | BindingFlags.Static); if (fieldInfo != null) { var val = fieldInfo.GetValue(CultureInfo.CurrentCulture); var newCul = val as CultureInfo; if (newCul != null) { Thread.CurrentThread.CurrentCulture = newCul; } } var dateTimePattern = string.Format("{0} {1}", Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern, Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern); if (string.IsNullOrEmpty(InputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Input Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugEvalResult(InputFormat, "Input Format", dataObject.Environment)); } var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams(TimeModifierType, "Add Time"), debugItem); AddDebugItem(new DebugEvalResult(TimeModifierAmountDisplay, "", dataObject.Environment), debugItem); _debugInputs.Add(debugItem); if (string.IsNullOrEmpty(OutputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Output Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugEvalResult(OutputFormat, "Output Format", dataObject.Environment)); } } if (DataListUtil.HasNegativeIndex(InputFormat)) { allErrors.AddError(string.Format("Negative Recordset Index for Input Format: {0}", InputFormat)); } if (DataListUtil.HasNegativeIndex(OutputFormat)) { allErrors.AddError(string.Format("Negative Recordset Index for Output Format: {0}", OutputFormat)); } if (DataListUtil.HasNegativeIndex(TimeModifierAmountDisplay)) { allErrors.AddError(string.Format("Negative Recordset Index for Add Time: {0}", TimeModifierAmountDisplay)); } if (!allErrors.HasErrors()) { var colItr = new WarewolfListIterator(); var dtItr = CreateDataListEvaluateIterator(string.IsNullOrEmpty(DateTime) ? GlobalConstants.CalcExpressionNow : DateTime, dataObject.Environment); colItr.AddVariableToIterateOn(dtItr); var ifItr = CreateDataListEvaluateIterator(InputFormat, dataObject.Environment); colItr.AddVariableToIterateOn(ifItr); var ofItr = CreateDataListEvaluateIterator(OutputFormat, dataObject.Environment); colItr.AddVariableToIterateOn(ofItr); var tmaItr = CreateDataListEvaluateIterator(TimeModifierAmountDisplay, dataObject.Environment); colItr.AddVariableToIterateOn(tmaItr); if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { IDateTimeOperationTO transObj = ConvertToDateTimeTo(colItr.FetchNextValue(dtItr), colItr.FetchNextValue(ifItr), colItr.FetchNextValue(ofItr), TimeModifierType, colItr.FetchNextValue(tmaItr) ); IDateTimeFormatter format = DateTimeConverterFactory.CreateFormatter(); string result; string error; if (format.TryFormat(transObj, out result, out error)) { string expression = Result; dataObject.Environment.Assign(expression, result); } else { allErrors.AddError(error); } } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment)); } } } } catch (Exception e) { Dev2Logger.Log.Error("DSFDateTime", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfDateTimeActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, StateType.After); } } }
/// <summary> /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity /// </summary> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); // Process if no errors try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = (dataObject.IsDebugMode()); toUpsert.ResourceID = dataObject.ResourceID; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IDev2DataListEvaluateIterator dtItr = CreateDataListEvaluateIterator(string.IsNullOrEmpty(DateTime) ? GlobalConstants.CalcExpressionNow : DateTime, executionId, compiler, colItr, allErrors); colItr.AddIterator(dtItr); IDev2DataListEvaluateIterator ifItr = CreateDataListEvaluateIterator(InputFormat, executionId, compiler, colItr, allErrors); colItr.AddIterator(ifItr); IDev2DataListEvaluateIterator ofItr = CreateDataListEvaluateIterator(OutputFormat, executionId, compiler, colItr, allErrors); colItr.AddIterator(ofItr); IDev2DataListEvaluateIterator tmaItr = CreateDataListEvaluateIterator(TimeModifierAmountDisplay, executionId, compiler, colItr, allErrors); colItr.AddIterator(tmaItr); if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(DateTime)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time", "Input"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(System.DateTime.Now.ToString(CultureInfo.CurrentCulture), "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugItemVariableParams(DateTime, "Input", dtItr.FetchEntry(), executionId)); } var dateTimePattern = string.Format("{0} {1}", CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern); if (string.IsNullOrEmpty(InputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Input Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugItemVariableParams(InputFormat, "Input Format", ifItr.FetchEntry(), executionId)); } var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams(TimeModifierType, "Add Time"), debugItem); AddDebugItem(new DebugItemVariableParams(TimeModifierAmountDisplay, "", tmaItr.FetchEntry(), executionId, true), debugItem); _debugInputs.Add(debugItem); if (string.IsNullOrEmpty(OutputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Output Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugItemVariableParams(OutputFormat, "Output Format", ofItr.FetchEntry(), executionId)); } } if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { IDateTimeOperationTO transObj = ConvertToDateTimeTo(colItr.FetchNextRow(dtItr).TheValue, colItr.FetchNextRow(ifItr).TheValue, colItr.FetchNextRow(ofItr).TheValue, TimeModifierType, colItr.FetchNextRow(tmaItr).TheValue ); //Create a DateTimeFomatter using the DateTimeConverterFactory.DONE IDateTimeFormatter format = DateTimeConverterFactory.CreateFormatter(); string result; string error; if (format.TryFormat(transObj, out result, out error)) { string expression = Result; //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result toUpsert.Add(expression, result); toUpsert.FlushIterationFrame(); } else { allErrors.AddError(error); } } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } allErrors.MergeErrors(errors); } } catch (Exception e) { Dev2Logger.Log.Error("DSFDateTime", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfDateTimeActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }