public void ChineseSolarTermToDateTime() { for (var i = 285; i < 360; i += 15) { Debug.WriteLine(OnSolarTerm.The(i).ToDateTime(2018).ToString("dd MM yyyy - HH:00:00")); } for (var i = 0; i < 285; i += 15) { Debug.WriteLine(OnSolarTerm.The(i).ToDateTime(2018).ToString("dd MM yyyy - HH:00:00")); } }
/// <summary> /// Méthode de parsing d'une expression. /// </summary> /// <param name="expression">Expression à parser.</param> /// <param name="year">Année.</param> /// <returns>Un <see cref="ParserResult"/> correspondant.</returns> public override ParserResult Parse(string expression, int year) { int GetLeapCorrection(int element, int animal) { return(animal.IsEven() ? animal <= (2 * element) ? 1 : 61 : animal <= (2 * element) + 1 ? 7 : 67); } var result = new ParserResult(); var regex = new Regex(Pattern.ToString()); var match = regex.Match(expression); if (match.Success) { var solarTerm = OnSolarTerm.The(int.Parse(match.Groups["Degrees"].Value)); var calculatedYear = year; if (match.Groups["Cycle"].Value.IsNotNullOrEmpty() && match.Groups["Element"].Value.IsNotNullOrEmpty() && match.Groups["Animal"].Value.IsNotNullOrEmpty()) { /* * Cas d'une date particulière. l'année passée en paramètre ne nous sert pas, on la calcule avec le cycle, l'élément et l'animal. * */ var cycle = int.Parse(match.Groups["Cycle"].Value); var element = (ChineseElement)Enum.Parse(typeof(ChineseElement), match.Groups["Element"].Value, true); var animal = (ChineseZodiac)Enum.Parse(typeof(ChineseZodiac), match.Groups["Animal"].Value, true); var leapCorrection = GetLeapCorrection((int)element, (int)animal); calculatedYear = (12 * (int)element) - (5 * (int)animal) + leapCorrection + (60 * cycle) - 2757; } var date = solarTerm.ToDateTime(calculatedYear); if (match.Groups["Day"].Value.IsNotNullOrEmpty()) { date = date + int.Parse(match.Groups["Day"].Value).Days() - 1.Days(); } result.DatesToAdd.Add(date); } return(result); }