ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/xmltv_parser/trunk/libxmltv/Extensions.cs
Revision: 196
Committed: Sat Mar 16 21:53:19 2013 UTC (9 years, 10 months ago) by william
File size: 1368 byte(s)
Log Message:

File Contents

# User Rev Content
1 william 141 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5    
6     namespace libxmltv
7     {
8 william 159 public static class DateTimeStringConverter
9 william 141 {
10     private const string DEFAULT_DATE_FORMAT = "yyyy/MM/dd hh:mm tt";
11     public static string ToDateTimeString(this DateTime dt)
12     {
13     return dt.ToDateTimeString(DateTimeStringConverter.DEFAULT_DATE_FORMAT);
14     }
15     public static string ToDateTimeString(this DateTime dt, IFormatProvider provider)
16     {
17     return dt.ToString(provider);
18     }
19     public static string ToDateTimeString(this DateTime dt, string format)
20     {
21     return dt.ToString(format);
22     }
23     public static string ToDateTimeString(this DateTime dt, string format, IFormatProvider provider)
24     {
25     return dt.ToString(format, provider);
26     }
27     }
28    
29 william 196 public static class extensions
30     {
31     /// <summary>
32     /// Break a list of items into chunks of a specific size
33     /// </summary>
34     public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunksize)
35     {
36     while (source.Any())
37     {
38     yield return source.Take(chunksize);
39     source = source.Skip(chunksize);
40     }
41     }
42     }
43 william 141 }