root/trunk/AprSharp/dev/src/AprTime.cs

Revision 59, 2.4 kB (checked in by DenisG, 4 years ago)

[AprSharp] Cosmetic. License region.

  • Property svn:eol-style set to native
Line 
1 //  AprSharp, a wrapper library around the Apache Portable Runtime Library
2 #region Copyright (C) 2004 SOFTEC sa.
3 //
4 //  This library is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU Lesser General Public
6 //  License as published by the Free Software Foundation; either
7 //  version 2.1 of the License, or (at your option) any later version.
8 //
9 //  This library is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 //  Lesser General Public License for more details.
13 //
14 //  You should have received a copy of the GNU Lesser General Public
15 //  License along with this library; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 //  Sources, support options and lastest version of the complete library
19 //  is available from:
20 //              http://www.softec.st/AprSharp
21 //             
22 //
23 //  Initial authors :
24 //              Denis Gervalle
25 //              Olivier Desaive
26 #endregion
27 //
28 using System;
29 using System.Text;
30 using System.Runtime.InteropServices;
31 using System.Diagnostics;
32
33 namespace Softec.AprSharp
34 {
35     public class AprTime
36     {
37         private AprTime()
38         {
39         }
40
41                 public const int APR_RFC822_DATE_LEN = 30;
42                 public const int APR_CTIME_LEN           = 25;
43
44         public static long Now()
45         {
46             return(Apr.apr_time_now());
47         }
48
49         public static string Rfc822Date(long value)
50         {
51             StringBuilder buf = new StringBuilder(APR_RFC822_DATE_LEN);
52             int res = Apr.apr_rfc822_date(buf,value);
53             if (res != 0)
54                 throw new AprException(res);
55             return(buf.ToString());
56         }
57
58         public static string CTime(long value)
59         {
60             StringBuilder buf = new StringBuilder(APR_CTIME_LEN);
61             int res = Apr.apr_ctime(buf,value);
62             if (res != 0)
63                 throw new AprException(res);
64             return(buf.ToString());
65         }
66        
67         public static long FromDateTime(DateTime dt)
68         {
69                 if(dt.Ticks < 621355968000000000)
70                         throw new AprException("A DateTime prior to 1/1/1970 is not convertible to AprTime");
71                 return( (dt.Ticks / 10) - 62135596800000000 );
72         }
73
74         public static DateTime ToDateTime(long at)
75         {
76                 return new DateTime((at + 62135596800000000) * 10);
77         }
78     }
79 }
Note: See TracBrowser for help on using the browser.