<commit_before>﻿using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using CollectionManager.DataTypes;

namespace osu_StreamCompanion.Code.Helpers
{
    public static class Helpers
    {
        public static T[] SubArray<T>(this T[] data, int index, int length)
        {
            T[] result = new T[length];
            Array.Copy(data, index, result, 0, length);
            return result;
        }
        [DebuggerStepThrough()]
        public static DateTime GetDateFromVersionString(string version)
        {
            try
            {
                return DateTime.ParseExact(version.TrimStart('v'), "yyMMdd.HH",
                    System.Globalization.CultureInfo.InvariantCulture);
            }
            catch
            {
                return DateTime.ParseExact(version.TrimStart('v'), "yyMMdd",
                    System.Globalization.CultureInfo.InvariantCulture);
            }
        }
        [DebuggerStepThrough()]
        public static T ExecWithTimeout<T>(Func<T> function, int timeout = 10000)
        {
            var task = Task<T>.Factory.StartNew(function);
            if (task.Wait(TimeSpan.FromMilliseconds(timeout)))
                return task.Result;
            else
                return default(T);
        }<commit_msg>Fix GetDateFromVersionString failing when running SC for the first time<commit_after>﻿using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using CollectionManager.DataTypes;

namespace osu_StreamCompanion.Code.Helpers
{
    public static class Helpers
    {
        public static T[] SubArray<T>(this T[] data, int index, int length)
        {
            T[] result = new T[length];
            Array.Copy(data, index, result, 0, length);
            return result;
        }
        [DebuggerStepThrough()]
        public static DateTime GetDateFromVersionString(string version)
        {
            if(version=="N/A")
                return DateTime.MinValue;
            try
            {
                return DateTime.ParseExact(version.TrimStart('v'), "yyMMdd.HH",
                    System.Globalization.CultureInfo.InvariantCulture);
            }
            catch
            {
                return DateTime.ParseExact(version.TrimStart('v'), "yyMMdd",
                    System.Globalization.CultureInfo.InvariantCulture);
            }
        }
        [DebuggerStepThrough()]
        public static T ExecWithTimeout<T>(Func<T> function, int timeout = 10000)
        {
            var task = Task<T>.Factory.StartNew(function);
            if (task.Wait(TimeSpan.FromMilliseconds(timeout)))
                return task.Result;
            else
                return default(T);
        }
{'fraction_non_alphanumeric': 0.09389503748661192, 'fraction_numerical': 0.004284184219921457, 'mean_word_length': 1.921793534932221, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '663760', 'n_tokens_mistral': 736, 'n_tokens_neox': 713, 'n_words': 160}