<commit_before>﻿using DbShell.Driver.Common.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DbShell.DataSet
{
    public class DateShiftFormula : FormulaDefinition
    {
        [XamlProperty]
        public DateTime OriginalValue { get; set; }

        [XamlProperty]
        public DateTime NewValue { get; set; }

        public TimeSpan GetDateDiff()
        {
            return NewValue - OriginalValue;
        }

        public override void WritePrefix(StringBuilder sb)
        {
            sb.AppendFormat("DATEADD(ms, {0}, ", (long)GetDateDiff().TotalMilliseconds);
        }

        public override void WritePostfix(StringBuilder sb)
        {
            sb.Append(")");
        }
    }
}<commit_msg>DateShift extension<commit_after>﻿using DbShell.Driver.Common.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DbShell.DataSet
{
    public class DateShiftFormula : FormulaDefinition
    {
        [XamlProperty]
        public string OriginalValue { get; set; }

        [XamlProperty]
        public string NewValue { get; set; }

        protected DateTime GetOriginalValue() => ConvertValue(OriginalValue);
        protected DateTime GetNewValue() => ConvertValue(NewValue);

        protected DateTime ConvertValue(string name)
        {
            switch (name)
            {
                case "TODAY":
                    return DateTime.Now.Date;
                case "NOW":
                    return DateTime.Now;
            }
            return DateTime.Parse(name);
        }

        public TimeSpan GetDateDiff()
        {
            return GetNewValue() - GetOriginalValue();
        }

        public override void WritePrefix(StringBuilder sb)
        {
            sb.AppendFormat("DATEADD(ms, {0}, ", (long)GetDateDiff().TotalMilliseconds);
        }

        public override void WritePostfix(StringBuilder sb)
        {
            sb.Append(")");
        }
    }
}
{'fraction_non_alphanumeric': 0.09144834404349975, 'fraction_numerical': 0.0009886307464162135, 'mean_word_length': 2.0481927710843375, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3204552', 'n_tokens_mistral': 530, 'n_tokens_neox': 516, 'n_words': 121}