54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
namespace Web12306.Servers.TrainSuggestion
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
|
|
public static class Cn12306SuggestionUtility
|
|
{
|
|
public static double TimeRangeLimitRadio = double.Parse(System.Configuration.ConfigurationManager.AppSettings["12306_trainsuggestion_maxradio"]);
|
|
|
|
public static readonly char[] BaseSeatCodes = "O219PM6430".ToArray();
|
|
|
|
public static TimeSpan GetTimeSpace(TimeSpan t1, TimeSpan t2)
|
|
{
|
|
var t = t2 - t1;
|
|
if (t.Ticks < 0)
|
|
t = t.Add(new TimeSpan(1, 0, 0, 0));
|
|
return t;
|
|
}
|
|
|
|
public static int GetStopTime(string stopTimeStr)
|
|
{
|
|
var m = Regex.Match(stopTimeStr, @"(\d+)·ÖÖÓ");
|
|
return m.Success ? int.Parse(m.Groups[1].Value) : 0;
|
|
}
|
|
|
|
public static TimeSpan GetStopTimeSpan(string stopTimeStr)
|
|
{
|
|
var m = Regex.Match(stopTimeStr, @"(\d+)·ÖÖÓ");
|
|
return m.Success ? new TimeSpan(0, int.Parse(m.Groups[1].Value), 0) : TimeSpan.Zero;
|
|
}
|
|
|
|
public static int GetTimeValue(string time)
|
|
{
|
|
var m = Regex.Match(time, @"0?(\d+):0?(\d+)");
|
|
return m.Success ? int.Parse(m.Groups[1].Value) * 60 + int.Parse(m.Groups[2].Value) : 0;
|
|
}
|
|
public static TimeSpan GetTimeValueSpan(string time)
|
|
{
|
|
var m = Regex.Match(time, @"0?(\d+):0?(\d+)");
|
|
return m.Success ? new TimeSpan(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), 0) : TimeSpan.Zero;
|
|
}
|
|
|
|
public static int GetTimeSpace(string time1, string time2)
|
|
{
|
|
var x1 = GetTimeValue(time1);
|
|
var x2 = GetTimeValue(time2);
|
|
|
|
return x1 <= x2 ? x2 - x1 : x2 + 24 * 60 - x1;
|
|
}
|
|
|
|
}
|
|
} |