Time.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // CoreUtil
  2. //
  3. // Copyright (C) 2012-2014 Daiyuu Nobori. All Rights Reserved.
  4. // Copyright (C) 2012-2014 SoftEther VPN Project at University of Tsukuba. All Rights Reserved.
  5. // Comments: Tetsuo Sugiyama, Ph.D.
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // version 2 as published by the Free Software Foundation.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License version 2
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. // THE LICENSE AGREEMENT IS ATTACHED ON THE SOURCE-CODE PACKAGE
  29. // AS "LICENSE.TXT" FILE. READ THE TEXT FILE IN ADVANCE TO USE THE SOFTWARE.
  30. //
  31. //
  32. // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN,
  33. // UNDER JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY,
  34. // MERGE, PUBLISH, DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS
  35. // SOFTWARE, THAT ANY JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS
  36. // SOFTWARE OR ITS CONTENTS, AGAINST US (SOFTETHER PROJECT, SOFTETHER
  37. // CORPORATION, DAIYUU NOBORI OR OTHER SUPPLIERS), OR ANY JURIDICAL
  38. // DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND OF USING, COPYING,
  39. // MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, AND/OR
  40. // SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
  41. // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO
  42. // EXCLUSIVE JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO,
  43. // JAPAN. YOU MUST WAIVE ALL DEFENSES OF LACK OF PERSONAL JURISDICTION
  44. // AND FORUM NON CONVENIENS. PROCESS MAY BE SERVED ON EITHER PARTY IN
  45. // THE MANNER AUTHORIZED BY APPLICABLE LAW OR COURT RULE.
  46. //
  47. // USE ONLY IN JAPAN. DO NOT USE IT IN OTHER COUNTRIES. IMPORTING THIS
  48. // SOFTWARE INTO OTHER COUNTRIES IS AT YOUR OWN RISK. SOME COUNTRIES
  49. // PROHIBIT ENCRYPTED COMMUNICATIONS. USING THIS SOFTWARE IN OTHER
  50. // COUNTRIES MIGHT BE RESTRICTED.
  51. //
  52. //
  53. // SOURCE CODE CONTRIBUTION
  54. // ------------------------
  55. //
  56. // Your contribution to SoftEther VPN Project is much appreciated.
  57. // Please send patches to us through GitHub.
  58. // Read the SoftEther VPN Patch Acceptance Policy in advance:
  59. // http://www.softether.org/5-download/src/9.patch
  60. //
  61. //
  62. // DEAR SECURITY EXPERTS
  63. // ---------------------
  64. //
  65. // If you find a bug or a security vulnerability please kindly inform us
  66. // about the problem immediately so that we can fix the security problem
  67. // to protect a lot of users around the world as soon as possible.
  68. //
  69. // Our e-mail address for security reports is:
  70. // softether-vpn-security [at] softether.org
  71. //
  72. // Please note that the above e-mail address is not a technical support
  73. // inquiry address. If you need technical assistance, please visit
  74. // http://www.softether.org/ and ask your question on the users forum.
  75. //
  76. // Thank you for your cooperation.
  77. //
  78. //
  79. // NO MEMORY OR RESOURCE LEAKS
  80. // ---------------------------
  81. //
  82. // The memory-leaks and resource-leaks verification under the stress
  83. // test has been passed before release this source code.
  84. using System;
  85. using System.Threading;
  86. using System.Data;
  87. using System.Data.Sql;
  88. using System.Data.SqlClient;
  89. using System.Data.SqlTypes;
  90. using System.Text;
  91. using System.Configuration;
  92. using System.Collections;
  93. using System.Collections.Generic;
  94. using System.Security.Cryptography;
  95. using System.Web;
  96. using System.Web.Security;
  97. using System.Web.UI;
  98. using System.Web.UI.WebControls;
  99. using System.Web.UI.WebControls.WebParts;
  100. using System.Web.UI.HtmlControls;
  101. using System.IO;
  102. using System.Drawing;
  103. using System.Drawing.Imaging;
  104. using System.Drawing.Drawing2D;
  105. using System.Diagnostics;
  106. using System.Web.Mail;
  107. namespace CoreUtil
  108. {
  109. class TimeHelper
  110. {
  111. internal Stopwatch Sw;
  112. internal long Freq;
  113. internal DateTime FirstDateTime;
  114. public TimeHelper()
  115. {
  116. FirstDateTime = DateTime.Now;
  117. Sw = new Stopwatch();
  118. Sw.Start();
  119. Freq = Stopwatch.Frequency;
  120. }
  121. public DateTime GetDateTime()
  122. {
  123. return FirstDateTime + this.Sw.Elapsed;
  124. }
  125. }
  126. public static class Time
  127. {
  128. static TimeHelper h = new TimeHelper();
  129. static TimeSpan baseTimeSpan = new TimeSpan(0, 0, 1);
  130. static public TimeSpan NowTimeSpan
  131. {
  132. get
  133. {
  134. return h.Sw.Elapsed.Add(baseTimeSpan);
  135. }
  136. }
  137. static public long NowLong100Usecs
  138. {
  139. get
  140. {
  141. return NowTimeSpan.Ticks;
  142. }
  143. }
  144. static public long NowLongMillisecs
  145. {
  146. get
  147. {
  148. return NowLong100Usecs / 10000;
  149. }
  150. }
  151. static public long Tick64
  152. {
  153. get
  154. {
  155. return NowLongMillisecs;
  156. }
  157. }
  158. static public double NowDouble
  159. {
  160. get
  161. {
  162. return (double)NowLong100Usecs / (double)10000000.0;
  163. }
  164. }
  165. static public DateTime NowDateTime
  166. {
  167. get
  168. {
  169. return h.GetDateTime();
  170. }
  171. }
  172. }
  173. }
  174. // Developed by SoftEther VPN Project at University of Tsukuba in Japan.
  175. // Department of Computer Science has dozens of overly-enthusiastic geeks.
  176. // Join us: http://www.tsukuba.ac.jp/english/admission/