public void TimeModifiers_Seconds_Negative_Expected_Correct_Subtraction()
        {
            const string inputString  = "2025/02/15 11:21:51 AM";
            const string formatString = "yyyy/mm/dd 12h:min:ss am/pm";

            var dateTimeFormatter = DateTimeConverterFactory.CreateFormatter();
            var dateTimeResult    = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "Seconds", -2, "");

            dateTimeFormatter.TryFormat(dateTimeResult, out string result, out string error);
            Assert.IsTrue(result == "2025/02/15 11:21:49 AM");
        }
        public void TimeModifiers_Split_Secs_Zero_Expected_No_Change()
        {
            const string inputString  = "2025/02/15 11:21:51 AM";
            const string formatString = "yyyy/mm/dd 12h:min:ss am/pm";

            var dateTimeFormatter = DateTimeConverterFactory.CreateFormatter();
            var dateTimeResult    = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "Milliseconds", 0, "");

            dateTimeFormatter.TryFormat(dateTimeResult, out string result, out string error);
            Assert.IsTrue(result == "2025/02/15 11:21:51 AM");
        }
        public void TimeModifiers_Days_Positive_Expected_Correct_Addition()
        {
            const string inputString  = "2025/06/15 11:21:51 AM";
            const string formatString = "yyyy/mm/dd 12h:min:ss am/pm";

            var dateTimeFormatter = DateTimeConverterFactory.CreateFormatter();
            var dateTimeResult    = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "Days", 30, "");

            dateTimeFormatter.TryFormat(dateTimeResult, out string result, out string error);
            Assert.IsTrue(result == "2025/07/15 11:21:51 AM");
        }
        public void TimeModifiers_Blank_Positive_Expected_No_Change()
        {
            const string inputString  = "2012/02/15 11:21:51 AM";
            const string formatString = "yyyy/mm/dd 12h:min:ss am/pm";

            var dateTimeFormatter = DateTimeConverterFactory.CreateFormatter();
            var dateTimeResult    = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "yyyy/mm/dd 12h:min:ss am/pm", "", 25, "");

            dateTimeFormatter.TryFormat(dateTimeResult, out string result, out string error);
            Assert.IsTrue(result == "2012/02/15 11:21:51 AM");
        }
        public void TryFormat_Converting_Date_To_ww_Expected_WeekReturnedInDoubleDigitFormat()
        {
            const string inputString  = "06-01-2013";
            const string formatString = "dd-mm-yyyy";

            var dateTimeFormatter = DateTimeConverterFactory.CreateFormatter();
            var dateTimeResult    = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "ww", "", 0, "");

            dateTimeFormatter.TryFormat(dateTimeResult, out string result, out string error);
            Assert.IsTrue(result == "02");
        }
        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 TimeModifiers_Seconds_Positive_Expected_Correct_Addition()
        {
            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:53 AM");
        }
        public void TimeModifiers_Days_Negative_Expected_Correct_Subtraction()
        {
            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/05/16 11:21:51 AM");
        }
        public void TryFormat_Converting_Date_To_Week_Expected_WeekofTheSpecifiedDataReturned()
        {
            string result;
            string error;
            string inputString  = "06-01-2013";
            string formatString = "dd-mm-yyyy";

            IDateTimeFormatter   formatter      = DateTimeConverterFactory.CreateFormatter();
            IDateTimeOperationTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeTO(inputString, formatString, "w", "", 0, "");

            formatter.TryFormat(dateTimeResult, out result, out error);
            Assert.IsTrue(result == "2");
        }
Example #10
0
        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");
        }
Example #11
0
        private void UpdateDatalist(IDSFDataObject dataObject, int update, ErrorResultTO allErrors)
        {
            var colItr = new WarewolfListIterator();

            var dtItr = CreateDataListEvaluateIterator(string.IsNullOrEmpty(DateTime) ? GlobalConstants.CalcExpressionNow : DateTime, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(dtItr);
            var ifItr = CreateDataListEvaluateIterator(InputFormat, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(ifItr);
            var ofItr = CreateDataListEvaluateIterator(OutputFormat, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(ofItr);
            var tmaItr = CreateDataListEvaluateIterator(TimeModifierAmountDisplay, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(tmaItr);

            if (!allErrors.HasErrors())
            {
                while (colItr.HasMoreData())
                {
                    var transObj = ConvertToDateTimeTo(colItr.FetchNextValue(dtItr),
                                                       colItr.FetchNextValue(ifItr),
                                                       colItr.FetchNextValue(ofItr),
                                                       TimeModifierType,
                                                       colItr.FetchNextValue(tmaItr)
                                                       );

                    var    format = DateTimeConverterFactory.CreateFormatter();
                    string result;
                    string error;
                    if (format.TryFormat(transObj, out result, out error))
                    {
                        var expression = Result;
                        dataObject.Environment.Assign(expression, result, update);
                    }
                    else
                    {
                        allErrors.AddError(error);
                    }
                }
                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                {
                    AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                }
            }
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     formatter = DateTimeConverterFactory.CreateFormatter();
 }
Example #13
0
        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);
                }
            }
        }
Example #14
0
        public void DateTimeConverterFactory_CreateFormatter()
        {
            var formatter = DateTimeConverterFactory.CreateFormatter();

            Assert.AreEqual(typeof(DateTimeFormatter), formatter.GetType());
        }
        /// <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);
                }
            }
        }