New method to set UTC time.
authorStefan Vogel <sv@exept.de>
Tue, 13 Jul 1999 12:56:03 +0200
changeset 4380 9f168c6f4beb
parent 4379 20ba95273826
child 4381 d8e1241c5c06
New method to set UTC time.
UnixOS.st
UnixOperatingSystem.st
--- a/UnixOS.st	Tue Jul 13 12:49:22 1999 +0200
+++ b/UnixOS.st	Tue Jul 13 12:56:03 1999 +0200
@@ -3968,21 +3968,21 @@
     "return some object filled with info for the file 'aPathName';
      the info (for which corresponding access methods are understood by
      the returned object) is:
-	 type            - a symbol giving the files type
-	 mode            - numeric access mode 
-	 uid             - owners user id
-	 gid             - owners group id
-	 size            - files size
-	 id              - files number (i.e. inode number)
-	 accessed        - last access time (as Timestamp)
-	 modified        - last modification time (as Timestamp)
-	 statusChanged   - last status change time (as Timestamp)
-	 alternativeName     - (windows only:) the MSDOS name of the file
-	 recordFormatNumeric - (VMS only:) numeric value of the recordFormat
-	 recordFormat        - (VMS only:) symbolic value of the recordFormat
-	 recordAttributes    - (VMS only:) recordAttributes
-	 fixedHeaderSize     - (VMS only:) fixed header size in a variable record format
-	 recordSize          - (VMS only:) record size.
+         type            - a symbol giving the files type
+         mode            - numeric access mode 
+         uid             - owners user id
+         gid             - owners group id
+         size            - files size
+         id              - files number (i.e. inode number)
+         accessed        - last access time (as Timestamp)
+         modified        - last modification time (as Timestamp)
+         statusChanged   - last status change time (as Timestamp)
+         alternativeName     - (windows only:) the MSDOS name of the file
+         recordFormatNumeric - (VMS only:) numeric value of the recordFormat
+         recordFormat        - (VMS only:) symbolic value of the recordFormat
+         recordAttributes    - (VMS only:) recordAttributes
+         fixedHeaderSize     - (VMS only:) fixed header size in a variable record format
+         recordSize          - (VMS only:) record size.
 
      Some of the fields may be returned as nil on systems which do not provide
      all of the information.
@@ -3994,10 +3994,7 @@
 
     |info type mode uid gid size id 
      atime mtime ctime 
-     aOStime mOStime cOStime
-     aYr aMon aDay aHr aMin aSec aMS
-     mYr mMon mDay mHr mMin mSec mMS
-     cYr cMon cDay cHr cMin cSec cMS|
+     aOStime mOStime cOStime|
 %{
     struct stat buf;
     int ret;
@@ -4006,101 +4003,95 @@
 
     if (__isString(aPathName)) {
 # ifdef TRACE_STAT_CALLS
-	printf("stat on '%s' for info\n", __stringVal(aPathName));
-# endif
-	__BEGIN_INTERRUPTABLE__
-	do {
-	    ret = stat((char *) __stringVal(aPathName), &buf);
-	} while ((ret < 0) && (errno == EINTR));
-	__END_INTERRUPTABLE__
-
-	if (ret < 0) {
-	    @global(LastErrorNumber) = __MKSMALLINT(errno);
-	    RETURN ( nil );
-	}
-	switch (buf.st_mode & S_IFMT) {
-	    case S_IFDIR:
-		type = @symbol(directory);
-		break;
-
-	    case S_IFREG:
-		type = @symbol(regular);
-		break;
+        printf("stat on '%s' for info\n", __stringVal(aPathName));
+# endif
+        __BEGIN_INTERRUPTABLE__
+        do {
+            ret = stat((char *) __stringVal(aPathName), &buf);
+        } while ((ret < 0) && (errno == EINTR));
+        __END_INTERRUPTABLE__
+
+        if (ret < 0) {
+            @global(LastErrorNumber) = __MKSMALLINT(errno);
+            RETURN ( nil );
+        }
+        switch (buf.st_mode & S_IFMT) {
+            case S_IFDIR:
+                type = @symbol(directory);
+                break;
+
+            case S_IFREG:
+                type = @symbol(regular);
+                break;
 # ifdef S_IFCHR
-	    case S_IFCHR:
-		type = @symbol(characterSpecial);
-		break;
+            case S_IFCHR:
+                type = @symbol(characterSpecial);
+                break;
 # endif
 # ifdef S_IFBLK
-	    case S_IFBLK:
-		type = @symbol(blockSpecial);
-		break;
+            case S_IFBLK:
+                type = @symbol(blockSpecial);
+                break;
 # endif
 # ifdef S_IFMPC
-	    case S_IFMPC:
-		type = @symbol(multiplexedCharacterSpecial);
-		break;
+            case S_IFMPC:
+                type = @symbol(multiplexedCharacterSpecial);
+                break;
 # endif
 # ifdef S_IFMPB
-	    case S_IFMPB:
-		type = @symbol(multiplexedBlockSpecial);
-		break;
+            case S_IFMPB:
+                type = @symbol(multiplexedBlockSpecial);
+                break;
 # endif
 # ifdef S_IFLNK
-	    case S_IFLNK:
-		type = @symbol(symbolicLink);
-		break;
+            case S_IFLNK:
+                type = @symbol(symbolicLink);
+                break;
 # endif
 # ifdef S_IFSOCK
-	    case S_IFSOCK:
-		type = @symbol(socket);
-		break;
+            case S_IFSOCK:
+                type = @symbol(socket);
+                break;
 # endif
 # ifdef S_IFIFO
-	    case S_IFIFO:
-		type = @symbol(fifo);
-		break;
-# endif
-	    default:
-		type = @symbol(unknown);
-		break;
-	}
-
-	ino = buf.st_ino;
-	id = __MKUINT(ino);
-
-	mode = __MKSMALLINT(buf.st_mode & 0777);
-	uid = __MKSMALLINT(buf.st_uid);
-	gid = __MKSMALLINT(buf.st_gid);
-	size = __MKUINT(buf.st_size);
-	aOStime = __MKUINT(buf.st_atime);
-	mOStime = __MKUINT(buf.st_mtime);
-	cOStime = __MKUINT(buf.st_ctime);
+            case S_IFIFO:
+                type = @symbol(fifo);
+                break;
+# endif
+            default:
+                type = @symbol(unknown);
+                break;
+        }
+
+        ino = buf.st_ino;
+        id = __MKUINT(ino);
+
+        mode = __MKSMALLINT(buf.st_mode & 0777);
+        uid = __MKSMALLINT(buf.st_uid);
+        gid = __MKSMALLINT(buf.st_gid);
+        size = __MKUINT(buf.st_size);
+        aOStime = __MKUINT(buf.st_atime);
+        mOStime = __MKUINT(buf.st_mtime);
+        cOStime = __MKUINT(buf.st_ctime);
     }
 %}.
     mode notNil ifTrue:[
-	aOStime notNil ifTrue:[
-	    atime := AbsoluteTime fromOSTime:(aOStime * 1000).
-	    mtime := AbsoluteTime fromOSTime:(mOStime * 1000).
-	    ctime := AbsoluteTime fromOSTime:(cOStime * 1000).
-	] ifFalse:[
-	    atime := AbsoluteTime day:aDay month:aMon year:aYr hour:aHr minutes:aMin seconds:aSec milliseconds:aMS.
-	    mtime := AbsoluteTime day:mDay month:mMon year:mYr hour:mHr minutes:mMin seconds:mSec milliseconds:mMS.
-	    ctime := AbsoluteTime day:cDay month:cMon year:cYr hour:cHr minutes:cMin seconds:cSec milliseconds:cMS.
-	].
-
-	info := FileStatusInfo
-		    type:type 
-		    mode:mode 
-		    uid:uid 
-		    gid:gid 
-		    size:size 
-		    id:id 
-		    accessed:atime 
-		    modified:mtime 
-		    statusChanged:ctime
-		    path:nil.
-	^ info
+        atime := AbsoluteTime fromOSTime:(aOStime * 1000).
+        mtime := AbsoluteTime fromOSTime:(mOStime * 1000).
+        ctime := AbsoluteTime fromOSTime:(cOStime * 1000).
+
+        info := FileStatusInfo
+                    type:type 
+                    mode:mode 
+                    uid:uid 
+                    gid:gid 
+                    size:size 
+                    id:id 
+                    accessed:atime 
+                    modified:mtime 
+                    statusChanged:ctime
+                    path:nil.
+        ^ info
    ].
    ^ self primitiveFailed
 
@@ -7100,6 +7091,44 @@
     "
 !
 
+computeOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
+    "return the OS-dependent time for the given time and day. 
+     The arguments are assumed to be in UTC Time"
+
+    |osSeconds|
+
+%{
+    struct tm tm;
+    TIME_T t;
+
+    if (__bothSmallInteger(y, m) 
+     && __bothSmallInteger(d, h)
+     && __bothSmallInteger(min, s)) {
+        tm.tm_hour = __intVal(h);
+        tm.tm_min = __intVal(min);
+        tm.tm_sec = __intVal(s);
+
+        tm.tm_year = __intVal(y) - 1900;
+        tm.tm_mon = __intVal(m) - 1;
+        tm.tm_mday = __intVal(d);
+        tm.tm_isdst = 0;
+
+        t = mktime(&tm);
+        osSeconds = __MKUINT((INT)t-TIMEZONE(tmPtr));
+    }
+%}.
+    osSeconds notNil ifTrue:[
+        ^ osSeconds * 1000 + millis
+    ].    
+    ^ self primitiveFailed
+
+    "
+     OperatingSystem computeOSTimeFromUTCYear:1970 month:1 day:1 hour:0 minute:0 seconds:0 millis:0
+     OperatingSystem computeOSTimeFromYear:1970 month:1 day:1 hour:0 minute:0 seconds:0 millis:0
+    "
+
+!
+
 computeOSTimeFromYear:y month:m day:d hour:h minute:min seconds:s millis:millis
     "return the OS-dependent time for the given time and day. 
      The arguments are assumed to be in localtime including
@@ -8613,6 +8642,6 @@
 !UnixOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/UnixOS.st,v 1.65 1999-06-09 13:44:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/UnixOS.st,v 1.66 1999-07-13 10:56:03 stefan Exp $'
 ! !
 UnixOperatingSystem initialize!
--- a/UnixOperatingSystem.st	Tue Jul 13 12:49:22 1999 +0200
+++ b/UnixOperatingSystem.st	Tue Jul 13 12:56:03 1999 +0200
@@ -3968,21 +3968,21 @@
     "return some object filled with info for the file 'aPathName';
      the info (for which corresponding access methods are understood by
      the returned object) is:
-	 type            - a symbol giving the files type
-	 mode            - numeric access mode 
-	 uid             - owners user id
-	 gid             - owners group id
-	 size            - files size
-	 id              - files number (i.e. inode number)
-	 accessed        - last access time (as Timestamp)
-	 modified        - last modification time (as Timestamp)
-	 statusChanged   - last status change time (as Timestamp)
-	 alternativeName     - (windows only:) the MSDOS name of the file
-	 recordFormatNumeric - (VMS only:) numeric value of the recordFormat
-	 recordFormat        - (VMS only:) symbolic value of the recordFormat
-	 recordAttributes    - (VMS only:) recordAttributes
-	 fixedHeaderSize     - (VMS only:) fixed header size in a variable record format
-	 recordSize          - (VMS only:) record size.
+         type            - a symbol giving the files type
+         mode            - numeric access mode 
+         uid             - owners user id
+         gid             - owners group id
+         size            - files size
+         id              - files number (i.e. inode number)
+         accessed        - last access time (as Timestamp)
+         modified        - last modification time (as Timestamp)
+         statusChanged   - last status change time (as Timestamp)
+         alternativeName     - (windows only:) the MSDOS name of the file
+         recordFormatNumeric - (VMS only:) numeric value of the recordFormat
+         recordFormat        - (VMS only:) symbolic value of the recordFormat
+         recordAttributes    - (VMS only:) recordAttributes
+         fixedHeaderSize     - (VMS only:) fixed header size in a variable record format
+         recordSize          - (VMS only:) record size.
 
      Some of the fields may be returned as nil on systems which do not provide
      all of the information.
@@ -3994,10 +3994,7 @@
 
     |info type mode uid gid size id 
      atime mtime ctime 
-     aOStime mOStime cOStime
-     aYr aMon aDay aHr aMin aSec aMS
-     mYr mMon mDay mHr mMin mSec mMS
-     cYr cMon cDay cHr cMin cSec cMS|
+     aOStime mOStime cOStime|
 %{
     struct stat buf;
     int ret;
@@ -4006,101 +4003,95 @@
 
     if (__isString(aPathName)) {
 # ifdef TRACE_STAT_CALLS
-	printf("stat on '%s' for info\n", __stringVal(aPathName));
-# endif
-	__BEGIN_INTERRUPTABLE__
-	do {
-	    ret = stat((char *) __stringVal(aPathName), &buf);
-	} while ((ret < 0) && (errno == EINTR));
-	__END_INTERRUPTABLE__
-
-	if (ret < 0) {
-	    @global(LastErrorNumber) = __MKSMALLINT(errno);
-	    RETURN ( nil );
-	}
-	switch (buf.st_mode & S_IFMT) {
-	    case S_IFDIR:
-		type = @symbol(directory);
-		break;
-
-	    case S_IFREG:
-		type = @symbol(regular);
-		break;
+        printf("stat on '%s' for info\n", __stringVal(aPathName));
+# endif
+        __BEGIN_INTERRUPTABLE__
+        do {
+            ret = stat((char *) __stringVal(aPathName), &buf);
+        } while ((ret < 0) && (errno == EINTR));
+        __END_INTERRUPTABLE__
+
+        if (ret < 0) {
+            @global(LastErrorNumber) = __MKSMALLINT(errno);
+            RETURN ( nil );
+        }
+        switch (buf.st_mode & S_IFMT) {
+            case S_IFDIR:
+                type = @symbol(directory);
+                break;
+
+            case S_IFREG:
+                type = @symbol(regular);
+                break;
 # ifdef S_IFCHR
-	    case S_IFCHR:
-		type = @symbol(characterSpecial);
-		break;
+            case S_IFCHR:
+                type = @symbol(characterSpecial);
+                break;
 # endif
 # ifdef S_IFBLK
-	    case S_IFBLK:
-		type = @symbol(blockSpecial);
-		break;
+            case S_IFBLK:
+                type = @symbol(blockSpecial);
+                break;
 # endif
 # ifdef S_IFMPC
-	    case S_IFMPC:
-		type = @symbol(multiplexedCharacterSpecial);
-		break;
+            case S_IFMPC:
+                type = @symbol(multiplexedCharacterSpecial);
+                break;
 # endif
 # ifdef S_IFMPB
-	    case S_IFMPB:
-		type = @symbol(multiplexedBlockSpecial);
-		break;
+            case S_IFMPB:
+                type = @symbol(multiplexedBlockSpecial);
+                break;
 # endif
 # ifdef S_IFLNK
-	    case S_IFLNK:
-		type = @symbol(symbolicLink);
-		break;
+            case S_IFLNK:
+                type = @symbol(symbolicLink);
+                break;
 # endif
 # ifdef S_IFSOCK
-	    case S_IFSOCK:
-		type = @symbol(socket);
-		break;
+            case S_IFSOCK:
+                type = @symbol(socket);
+                break;
 # endif
 # ifdef S_IFIFO
-	    case S_IFIFO:
-		type = @symbol(fifo);
-		break;
-# endif
-	    default:
-		type = @symbol(unknown);
-		break;
-	}
-
-	ino = buf.st_ino;
-	id = __MKUINT(ino);
-
-	mode = __MKSMALLINT(buf.st_mode & 0777);
-	uid = __MKSMALLINT(buf.st_uid);
-	gid = __MKSMALLINT(buf.st_gid);
-	size = __MKUINT(buf.st_size);
-	aOStime = __MKUINT(buf.st_atime);
-	mOStime = __MKUINT(buf.st_mtime);
-	cOStime = __MKUINT(buf.st_ctime);
+            case S_IFIFO:
+                type = @symbol(fifo);
+                break;
+# endif
+            default:
+                type = @symbol(unknown);
+                break;
+        }
+
+        ino = buf.st_ino;
+        id = __MKUINT(ino);
+
+        mode = __MKSMALLINT(buf.st_mode & 0777);
+        uid = __MKSMALLINT(buf.st_uid);
+        gid = __MKSMALLINT(buf.st_gid);
+        size = __MKUINT(buf.st_size);
+        aOStime = __MKUINT(buf.st_atime);
+        mOStime = __MKUINT(buf.st_mtime);
+        cOStime = __MKUINT(buf.st_ctime);
     }
 %}.
     mode notNil ifTrue:[
-	aOStime notNil ifTrue:[
-	    atime := AbsoluteTime fromOSTime:(aOStime * 1000).
-	    mtime := AbsoluteTime fromOSTime:(mOStime * 1000).
-	    ctime := AbsoluteTime fromOSTime:(cOStime * 1000).
-	] ifFalse:[
-	    atime := AbsoluteTime day:aDay month:aMon year:aYr hour:aHr minutes:aMin seconds:aSec milliseconds:aMS.
-	    mtime := AbsoluteTime day:mDay month:mMon year:mYr hour:mHr minutes:mMin seconds:mSec milliseconds:mMS.
-	    ctime := AbsoluteTime day:cDay month:cMon year:cYr hour:cHr minutes:cMin seconds:cSec milliseconds:cMS.
-	].
-
-	info := FileStatusInfo
-		    type:type 
-		    mode:mode 
-		    uid:uid 
-		    gid:gid 
-		    size:size 
-		    id:id 
-		    accessed:atime 
-		    modified:mtime 
-		    statusChanged:ctime
-		    path:nil.
-	^ info
+        atime := AbsoluteTime fromOSTime:(aOStime * 1000).
+        mtime := AbsoluteTime fromOSTime:(mOStime * 1000).
+        ctime := AbsoluteTime fromOSTime:(cOStime * 1000).
+
+        info := FileStatusInfo
+                    type:type 
+                    mode:mode 
+                    uid:uid 
+                    gid:gid 
+                    size:size 
+                    id:id 
+                    accessed:atime 
+                    modified:mtime 
+                    statusChanged:ctime
+                    path:nil.
+        ^ info
    ].
    ^ self primitiveFailed
 
@@ -7100,6 +7091,44 @@
     "
 !
 
+computeOSTimeFromUTCYear:y month:m day:d hour:h minute:min second:s millisecond:millis
+    "return the OS-dependent time for the given time and day. 
+     The arguments are assumed to be in UTC Time"
+
+    |osSeconds|
+
+%{
+    struct tm tm;
+    TIME_T t;
+
+    if (__bothSmallInteger(y, m) 
+     && __bothSmallInteger(d, h)
+     && __bothSmallInteger(min, s)) {
+        tm.tm_hour = __intVal(h);
+        tm.tm_min = __intVal(min);
+        tm.tm_sec = __intVal(s);
+
+        tm.tm_year = __intVal(y) - 1900;
+        tm.tm_mon = __intVal(m) - 1;
+        tm.tm_mday = __intVal(d);
+        tm.tm_isdst = 0;
+
+        t = mktime(&tm);
+        osSeconds = __MKUINT((INT)t-TIMEZONE(tmPtr));
+    }
+%}.
+    osSeconds notNil ifTrue:[
+        ^ osSeconds * 1000 + millis
+    ].    
+    ^ self primitiveFailed
+
+    "
+     OperatingSystem computeOSTimeFromUTCYear:1970 month:1 day:1 hour:0 minute:0 seconds:0 millis:0
+     OperatingSystem computeOSTimeFromYear:1970 month:1 day:1 hour:0 minute:0 seconds:0 millis:0
+    "
+
+!
+
 computeOSTimeFromYear:y month:m day:d hour:h minute:min seconds:s millis:millis
     "return the OS-dependent time for the given time and day. 
      The arguments are assumed to be in localtime including
@@ -8613,6 +8642,6 @@
 !UnixOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.65 1999-06-09 13:44:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.66 1999-07-13 10:56:03 stefan Exp $'
 ! !
 UnixOperatingSystem initialize!