<commit_before>﻿using System;
using System.Globalization;

#if NETFX || WINDOWS_PHONE
using System.Windows;
using System.Windows.Data;
#elif (WINDOWS_APP || WINDOWS_PHONE_APP)
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
#endif

namespace ValueConverters
{
    public abstract class DateTimeConverterBase : ConverterBase
    {
        protected const string DefaultFormat = "g";
        protected const string DefaultMinValueString = "";

        public abstract string Format { get; set; }
        public abstract string MinValueString { get; set; }

        protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || (DateTime)value == DateTime.MinValue)
            {
                return this.MinValueString;
            }

            if (targetType == typeof(string))
            {
                return ((DateTime)value).ToLocalTime().ToString(this.Format, culture);
            }

            return UnsetValue;
        }
    }
}<commit_msg>Refactor Convert logic in DateTimeConverterBase<commit_after>﻿using System;
using System.Globalization;

#if NETFX || WINDOWS_PHONE
using System.Windows;
using System.Windows.Data;
#elif (WINDOWS_APP || WINDOWS_PHONE_APP)
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
#endif

namespace ValueConverters
{
    public abstract class DateTimeConverterBase : ConverterBase
    {
        protected const string DefaultFormat = "g";
        protected const string DefaultMinValueString = "";

        public abstract string Format { get; set; }
        public abstract string MinValueString { get; set; }

        protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (value is DateTime)
                {
                    var dateTime = (DateTime)value;
                    if (dateTime == DateTime.MinValue)
                    {
                        return this.MinValueString;
                    }
                    return dateTime.ToLocalTime().ToString(this.Format, culture);
                }
            }

            return UnsetValue;
        }

        protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (value is DateTime)
                {
                    return (DateTime)value;
                }
                var str = value as string;
                if (str != null)
                {
                    DateTime resultDateTime;
                    DateTime.TryParse(str, out resultDateTime);
                    return resultDateTime;
                }
            }
            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.07665260196905767, 'fraction_numerical': 0.0, 'mean_word_length': 1.767509727626459, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4432395', 'n_tokens_mistral': 703, 'n_tokens_neox': 673, 'n_words': 192}