WikiCrawler/Tasks/Commons/TakenOnTemplate.cs
/// <summary>
/// Tries to convert the date to ISO YYYY-MM-DD, YYYY-MM, or YYYY. Very conservative, prefers failing to being wrong.
/// </summary>
Tries to convert the date to ISO YYYY-MM-DD, YYYY-MM, or YYYY. Very conservative, prefers failing to being wrong.
Tries to convert the date to ISO YYYY - MM - DD YYYY - MM or YYYY . Very conservative prefers failing to being wrong .
public static string DateToISO(string date, out bool hasDay)
		{
			date = date.Trim();
			string y = "";
			string m = "";
			string d = "";
			foreach (Regex rex in s_Dates)
			{
				Match match = rex.Match(date);
				if (match.Success)
				{
					y = match.Groups["y"].Value;
					m = match.Groups["m"].Value;
					foreach (string key in monthnames.Keys)
					{
						if (key.Equals(m, StringComparison.InvariantCultureIgnoreCase))
						{
							m = monthnames[key];
							break;
						}
					}
					d = match.Groups["d"].Value;
					break;
				}
			}
			if (y.Length != 4 || m.Length > 2 || d.Length > 2)
			{
				hasDay = false;
				return "";
			}
			try
			{
				int.Parse(y);
				if (!string.IsNullOrEmpty(m))
					int.Parse(m);
				if (!string.IsNullOrEmpty(d))
					int.Parse(d);
			}
			catch (FormatException)
			{
				hasDay = false;
				return "";
			}
			hasDay = false;
			string res = "";
			if (!string.IsNullOrEmpty(y))
			{
				res += PadLeft(y, 4, '0');
				if (!string.IsNullOrEmpty(m))
				{
					res += "-" + PadLeft(m, 2, '0');
					if (!string.IsNullOrEmpty(d))
					{
						hasDay = true;
						res += "-" + PadLeft(d, 2, '0');
					}
				}
			}
			return res;
		}
public static string DateToISO ( string date , out bool hasDay ) { date = date . Trim ( ) ; string y = " " ; string m = " " ; string d = " " ; foreach ( Regex rex in s_Dates ) { Match match = rex . Match ( date ) ; if ( match . Success ) { y = match . Groups [ " " ] . Value ; m = match . Groups [ " " ] . Value ; foreach ( string key in monthnames . Keys ) { if ( key . Equals ( m , StringComparison . InvariantCultureIgnoreCase ) ) { m = monthnames [ key ] ; break ; } } d = match . Groups [ " " ] . Value ; break ; } } if ( y . Length != 4 || m . Length > 2 || d . Length > 2 ) { hasDay = false ; return " " ; } try { int . Parse ( y ) ; if ( ! string . IsNullOrEmpty ( m ) ) int . Parse ( m ) ; if ( ! string . IsNullOrEmpty ( d ) ) int . Parse ( d ) ; } catch ( FormatException ) { hasDay = false ; return " " ; } hasDay = false ; string res = " " ; if ( ! string . IsNullOrEmpty ( y ) ) { res += PadLeft ( y , 4 , ' ' ) ; if ( ! string . IsNullOrEmpty ( m ) ) { res += " " + PadLeft ( m , 2 , ' ' ) ; if ( ! string . IsNullOrEmpty ( d ) ) { hasDay = true ; res += " " + PadLeft ( d , 2 , ' ' ) ; } } } return res ; }
Tries to convert the date to ISO YYYY-MM-DD, YYYY-MM, or YYYY.
Tries to convert the date to ISO YYYY - MM - DD YYYY - MM or YYYY .
//Try to match against each available regex //verify that these are valid numbers
date
string
bool
out