![]() |
ZenWINX Architecture - Reference Manual - Guides |
|
00001 /* 00002 * ZenWINX - WIndows Native eXtended library. 00003 * Copyright (c) 2009 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #include "ntndk.h" 00028 #include "zenwinx.h" 00029 00036 ULONGLONG __stdcall winx_str2time(char *string) 00037 { 00038 ULONGLONG time = 0; 00039 char buffer[128] = ""; 00040 int index = 0; 00041 int i; 00042 char c; 00043 ULONGLONG k; 00044 00045 for(i = 0;; i++){ /* loop through all characters of the string */ 00046 c = string[i]; 00047 if(!c) break; 00048 if(c >= '0' && c <= '9'){ 00049 buffer[index] = c; 00050 index++; 00051 } 00052 00053 k = 0; 00054 c = (char)toupper((int)c); 00055 switch(c){ 00056 case 'S': 00057 k = 1; 00058 break; 00059 case 'M': 00060 k = 60; 00061 break; 00062 case 'H': 00063 k = 3600; 00064 break; 00065 case 'D': 00066 k = 3600 * 24; 00067 break; 00068 case 'Y': 00069 k = 3600 * 24 * 356; 00070 break; 00071 } 00072 if(k){ 00073 buffer[index] = 0; 00074 index = 0; 00075 time += k * _atoi64(buffer); 00076 } 00077 } 00078 return time; 00079 } 00080 00090 int __stdcall winx_time2str(ULONGLONG time,char *buffer,int size) 00091 { 00092 ULONG y,d,h,m,s; 00093 ULONG t; 00094 int result; 00095 00096 t = (ULONG)time; /* because w2k has no _aulldvrm() call in ntdll.dll */ 00097 y = t / (3600 * 24 * 356); 00098 t = t % (3600 * 24 * 356); 00099 d = t / (3600 * 24); 00100 t = t % (3600 * 24); 00101 h = t / 3600; 00102 t = t % 3600; 00103 m = t / 60; 00104 s = t % 60; 00105 00106 result = _snprintf(buffer,size - 1, 00107 "%uy %ud %uh %um %us", 00108 y,d,h,m,s); 00109 buffer[size - 1] = 0; 00110 return result; 00111 } 00112