Beispiel #1
0
 protected override bool InitSection(Talk section)
 {
     section.LastActivity = section.FullText
                            .Split('\n')
                            .SelectMany(comment => DateRegex.Matches(comment).OfType <Match>())
                            .Max(comment => TryParseDate(comment));
     return(true);
 }
Beispiel #2
0
        /// <summary>
        /// Parse date and time string
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static DateTime Parse(string text)
        {
            DateTime result = DateTime.MinValue;

            if (String.IsNullOrEmpty(text))
            {
                return(result);
            }

            text = text.Trim();
            int    n;
            Match  match;
            string s;

            match = DateRegex.Match(text);

            if (!match.Success)
            {
                match = null;
            }

            if (null == match)
            {
                match = NumericDateRegex.Match(text);
                if (!match.Success)
                {
                    match = null;
                }
            }

            if (null != match)
            {
                s = match.Groups["year"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddYears(n - 1);
                }
                s = match.Groups["month"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    if (n > 12)
                    {
                        return(DateTime.MinValue);
                    }
                    result = result.AddMonths(n - 1);
                }
                s = match.Groups["day"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    switch (result.Month)
                    {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:
                        if (n > 31)
                        {
                            return(DateTime.MinValue);
                        }
                        break;

                    case 2:
                        bool leap = (0 == result.Year % 4) && (0 < result.Year % 100 || 0 == result.Year % 400);
                        if (n > 28 + (leap ? 1 : 0))
                        {
                            return(DateTime.MinValue);
                        }
                        break;

                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        if (n > 30)
                        {
                            return(DateTime.MinValue);
                        }
                        break;
                    }
                    result = result.AddDays(n - 1);
                }
                text = text.Substring(0, match.Index) + text.Substring(match.Index + match.Length);
            }

            match = TimeRegex.Match(text);

            if (match.Success)
            {
                s = match.Groups["hour"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddHours(n);
                }
                s = match.Groups["minute"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddMinutes(n);
                }
                s = match.Groups["second"].Value;
                if (!string.IsNullOrEmpty(s) && 0 < (n = int.Parse(s)))
                {
                    result = result.AddSeconds(n);
                }
                if (!string.IsNullOrEmpty(match.Groups["fraction"].Value))
                {
                    double d = double.Parse(string.Concat("0.", match.Groups["fraction"])
                                            , System.Globalization.NumberStyles.AllowDecimalPoint
                                            , System.Globalization.CultureInfo.InvariantCulture);
                    if (d > 0)
                    {
                        long t = (long)(TimeSpan.TicksPerSecond * d);
                        result = result.AddTicks(t);
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// 指定したResSetを
        /// 設定されているスキンを使用して文字列形式に変換
        /// </summary>
        /// <param name="resSet"></param>
        /// <returns></returns>
        public override string Convert(ResSet resSet)
        {
            if (!resSet.Visible)
            {
                return(String.Empty);
            }

            if (resSet.DateString == "透明あぼーん")
            {
                return(String.Empty);
            }

            /*
             * if (resSet.IsABone) {
             *      resSet = ResSet.ABone(resSet, ABoneType.NG, "");
             *      resSet.Email = String.Empty;
             * }*/

            // 使用するスキン
            string skinhtml = resSet.IsNew ? newResSkin : resSkin;
            string dateonly, body;

            // 本分からtagを取り除く
            body = resSet.Body;
            body = Regex.Replace(body, "<a[^>]+>(?<uri>[^<]*)</a>", "${uri}", RegexOptions.IgnoreCase);
            body = Regex.Replace(body, "<(?!br|hr)[^>]+>", "");

            buffer.Append(body);
            buffer.Replace("<br>", "\r\n");
            buffer.Replace("<hr>", "\r\n ————————————————————\r\n");
            buffer.Replace("&gt;", ">");
            buffer.Replace("&lt;", "<");
            body = buffer.ToString();
            buffer.Remove(0, buffer.Length);

            #region 日付とIDを作成
            dateonly = resSet.DateString;
            Match m = Regex.Match(resSet.DateString, "( ID:)|(\\[)");

            if (m.Success)
            {
                dateonly = resSet.DateString.Substring(0, m.Index);
            }
            #endregion

#if REGEX_REPLACE
            skinhtml = PlainNumberRegex.Replace(skinhtml, resSet.Index.ToString());
            skinhtml = IDRegex.Replace(skinhtml, resSet.ID);
            skinhtml = NameRegex.Replace(skinhtml, resSet.Name);
            skinhtml = EmailRegex.Replace(skinhtml, resSet.Email);
            skinhtml = DateRegex.Replace(skinhtml, resSet.DateString);
            skinhtml = DateOnlyRegex.Replace(skinhtml, dateonly);
            skinhtml = BodyRegex.Replace(skinhtml, body);
#else
            buffer.Append(skinhtml);
            buffer.Replace("<PLAINNUMBER/>", resSet.Index.ToString());
            buffer.Replace("<ID/>", resSet.ID);
            buffer.Replace("<NAME/>", HtmlTextUtility.RemoveTag(resSet.Name));
            buffer.Replace("<MAIL/>", resSet.Email);
            buffer.Replace("<DATE/>", resSet.DateString);
            buffer.Replace("<DATEONLY/>", dateonly);
            buffer.Replace("<MESSAGE/>", body);
            skinhtml = buffer.ToString();
            buffer.Remove(0, buffer.Length);
#endif

            return(skinhtml);
        }
 private static bool HasDateInPath(string file)
 {
     return(DateRegex.IsMatch(file));
 }