7441 containing (full-) year, month, day, hour, minute and seconds, |
7447 containing (full-) year, month, day, hour, minute and seconds, |
7442 offset to UTC, daylight savings time flag, milliseconds, |
7448 offset to UTC, daylight savings time flag, milliseconds, |
7443 dayInYear (1..) and dayInWeek (1..). |
7449 dayInYear (1..) and dayInWeek (1..). |
7444 Conversion is to localtime including any daylight saving adjustments." |
7450 Conversion is to localtime including any daylight saving adjustments." |
7445 |
7451 |
|
7452 |millis osSeconds ret| |
|
7453 |
|
7454 millis := osTime \\ 1000. |
|
7455 osSeconds := osTime // 1000. |
|
7456 ret := self fillTimeAndDateFromSeconds:osSeconds into:(Array new:11). |
|
7457 ret at:9 put:millis. |
|
7458 ^ ret |
|
7459 |
|
7460 " |
|
7461 OperatingSystem computeTimeAndDateFrom:0 |
|
7462 OperatingSystem computeTimeAndDateFrom:1011 |
|
7463 " |
|
7464 ! |
|
7465 |
|
7466 computeTimePartsOf:osTime for:aBlock |
|
7467 "compute hours, minutes, seconds and milliseconds from the osTime |
|
7468 and evaluate the argument, a 4-arg block with these. |
|
7469 Conversion is to localtime including any daylight saving adjustments." |
|
7470 |
|
7471 |hours minutes seconds millis osSeconds i| |
|
7472 |
|
7473 osSeconds := osTime // 1000. |
|
7474 millis := osTime \\ 1000. |
|
7475 %{ |
|
7476 struct tm *tmPtr; |
|
7477 INT t; |
|
7478 TIME_T tt; |
|
7479 |
|
7480 t = __longIntVal(osSeconds); |
|
7481 tt = (TIME_T)t; |
|
7482 |
|
7483 tmPtr = localtime(&tt); |
|
7484 hours = __MKSMALLINT(tmPtr->tm_hour); |
|
7485 minutes = __MKSMALLINT(tmPtr->tm_min); |
|
7486 seconds = __MKSMALLINT(tmPtr->tm_sec); |
|
7487 %}. |
|
7488 hours isNil ifTrue:[ |
|
7489 i := self computeTimeAndDateFrom:osTime. |
|
7490 hours := i at:4. |
|
7491 minutes := i at:5. |
|
7492 seconds := i at:6. |
|
7493 ]. |
|
7494 aBlock value:hours value:minutes value:seconds value:millis |
|
7495 |
|
7496 " |
|
7497 OperatingSystem computeTimePartsOf:100 for:[:h :m :s :milli | |
|
7498 h printCR. m printCR. s printCR. millis printCR |
|
7499 ] |
|
7500 " |
|
7501 ! |
|
7502 |
|
7503 computeUTCTimeAndDateFrom:osTime |
|
7504 "given an OS-dependent time in osTime, return an Array |
|
7505 containing year, month, day, hour, minute and seconds, |
|
7506 offset to UTC, daylight savings time flag, milliseconds, |
|
7507 dayInYear (1..) and dayInWeek (1..). |
|
7508 Conversion is to UTC." |
|
7509 |
7446 |low hi year month day hours minutes seconds millis utcOffset |
7510 |low hi year month day hours minutes seconds millis utcOffset |
7447 dst yDay wDay osSeconds ret| |
7511 dst yDay wDay osSeconds ret| |
7448 |
7512 |
7449 millis := osTime \\ 1000. |
7513 millis := osTime \\ 1000. |
7450 osSeconds := osTime // 1000. |
7514 osSeconds := osTime // 1000. |
7451 %{ |
7515 %{ |
7452 struct tm *tmPtr; |
7516 struct tm *tmPtr; |
7453 struct tm *gmTmPtr; |
7517 struct tm *gmTmPtr; |
7454 INT t; |
7518 long t; |
7455 TIME_T tt; |
|
7456 |
7519 |
7457 t = __longIntVal(osSeconds); |
7520 t = __longIntVal(osSeconds); |
7458 tt = (TIME_T)t; |
7521 |
7459 |
7522 tmPtr = gmtime(&t); |
7460 tmPtr = localtime(&tt); |
|
7461 hours = __MKSMALLINT(tmPtr->tm_hour); |
7523 hours = __MKSMALLINT(tmPtr->tm_hour); |
7462 minutes = __MKSMALLINT(tmPtr->tm_min); |
7524 minutes = __MKSMALLINT(tmPtr->tm_min); |
7463 seconds = __MKSMALLINT(tmPtr->tm_sec); |
7525 seconds = __MKSMALLINT(tmPtr->tm_sec); |
7464 |
7526 |
7465 year = __MKSMALLINT(tmPtr->tm_year + 1900); |
7527 year = __MKSMALLINT(tmPtr->tm_year + 1900); |
7466 month = __MKSMALLINT(tmPtr->tm_mon + 1); |
7528 month = __MKSMALLINT(tmPtr->tm_mon + 1); |
7467 day = __MKSMALLINT(tmPtr->tm_mday); |
7529 day = __MKSMALLINT(tmPtr->tm_mday); |
7468 |
7530 |
7469 yDay = __MKSMALLINT(tmPtr->tm_yday+1); |
7531 yDay = __MKSMALLINT(tmPtr->tm_yday + 1); |
7470 wDay = __MKSMALLINT(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday); |
7532 wDay = __MKSMALLINT(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday); |
7471 |
7533 |
7472 if (tmPtr->tm_isdst == 0) { |
7534 if (tmPtr->tm_isdst == 0) { |
7473 dst = false; |
7535 dst = false; |
7474 utcOffset = __MKINT(TIMEZONE(tmPtr)); |
7536 utcOffset = __MKINT(TIMEZONE(tmPtr)); |
7495 ret at:10 put:yDay. |
7557 ret at:10 put:yDay. |
7496 ret at:11 put:wDay. |
7558 ret at:11 put:wDay. |
7497 ^ ret |
7559 ^ ret |
7498 |
7560 |
7499 " |
7561 " |
7500 OperatingSystem computeTimeAndDateFrom:0 |
7562 OperatingSystem computeUTCTimeAndDateFrom:0 |
7501 " |
7563 " |
7502 ! |
7564 ! |
7503 |
7565 |
7504 computeTimePartsOf:osTime for:aBlock |
7566 computeUTCTimePartsOf:osTime for:aBlock |
7505 "compute hours, minutes, seconds and milliseconds from the osTime |
7567 "compute hours, minutes, seconds and milliseconds from the osTime |
7506 and evaluate the argument, a 4-arg block with these. |
7568 and evaluate the argument, a 4-arg block with these. |
7507 Conversion is to localtime including any daylight saving adjustments." |
7569 Conversion is to UTC." |
7508 |
7570 |
7509 |hours minutes seconds millis osSeconds| |
7571 |hours minutes seconds millis osSeconds| |
7510 |
7572 |
7511 osSeconds := osTime // 1000. |
7573 osSeconds := osTime // 1000. |
7512 millis := osTime \\ 1000. |
7574 millis := osTime \\ 1000. |
7513 %{ |
7575 %{ |
7514 struct tm *tmPtr; |
7576 struct tm *tmPtr; |
7515 INT t; |
7577 long t; |
7516 TIME_T tt; |
|
7517 |
7578 |
7518 t = __longIntVal(osSeconds); |
7579 t = __longIntVal(osSeconds); |
7519 tt = (TIME_T)t; |
7580 |
7520 |
7581 tmPtr = gmtime(&t); |
7521 tmPtr = localtime(&tt); |
|
7522 hours = __MKSMALLINT(tmPtr->tm_hour); |
7582 hours = __MKSMALLINT(tmPtr->tm_hour); |
7523 minutes = __MKSMALLINT(tmPtr->tm_min); |
7583 minutes = __MKSMALLINT(tmPtr->tm_min); |
7524 seconds = __MKSMALLINT(tmPtr->tm_sec); |
7584 seconds = __MKSMALLINT(tmPtr->tm_sec); |
7525 %}. |
7585 %}. |
7526 aBlock value:hours value:minutes value:seconds value:millis |
7586 aBlock value:hours value:minutes value:seconds value:millis |
7527 |
7587 |
7528 " |
7588 " |
7529 OperatingSystem computeTimePartsOf:100 for:[:h :m :s :milli | |
7589 OperatingSystem computeUTCTimePartsOf:100 for:[:h :m :s :milli | |
7530 h printCR. m printCR. s printCR. millis printCR |
7590 h printCR. m printCR. s printCR. milli printCR |
7531 ] |
7591 ] |
7532 " |
7592 " |
7533 ! |
7593 ! |
7534 |
7594 |
7535 computeUTCTimeAndDateFrom:osTime |
7595 fillTimeAndDateFromSeconds:osSeconds into:timeArray |
7536 "given an OS-dependent time in osTime, return an Array |
7596 "fill the array with os-time components. |
7537 containing year, month, day, hour, minute and seconds, |
7597 An internal helper" |
7538 offset to UTC, daylight savings time flag, milliseconds, |
7598 |
7539 dayInYear (1..) and dayInWeek (1..). |
7599 |low hi year month day hours minutes seconds utcOffset |
7540 Conversion is to UTC." |
7600 dst yDay wDay | |
7541 |
7601 |
7542 |low hi year month day hours minutes seconds millis utcOffset |
|
7543 dst yDay wDay osSeconds ret| |
|
7544 |
|
7545 millis := osTime \\ 1000. |
|
7546 osSeconds := osTime // 1000. |
|
7547 %{ |
7602 %{ |
7548 struct tm *tmPtr; |
7603 struct tm *tmPtr; |
7549 struct tm *gmTmPtr; |
7604 struct tm *gmTmPtr; |
7550 long t; |
7605 INT t; |
|
7606 TIME_T tt; |
7551 |
7607 |
7552 t = __longIntVal(osSeconds); |
7608 t = __longIntVal(osSeconds); |
7553 |
7609 tt = (TIME_T)t; |
7554 tmPtr = gmtime(&t); |
7610 |
|
7611 tmPtr = localtime(&tt); |
7555 hours = __MKSMALLINT(tmPtr->tm_hour); |
7612 hours = __MKSMALLINT(tmPtr->tm_hour); |
7556 minutes = __MKSMALLINT(tmPtr->tm_min); |
7613 minutes = __MKSMALLINT(tmPtr->tm_min); |
7557 seconds = __MKSMALLINT(tmPtr->tm_sec); |
7614 seconds = __MKSMALLINT(tmPtr->tm_sec); |
7558 |
7615 |
7559 year = __MKSMALLINT(tmPtr->tm_year + 1900); |
7616 year = __MKSMALLINT(tmPtr->tm_year + 1900); |
7560 month = __MKSMALLINT(tmPtr->tm_mon + 1); |
7617 month = __MKSMALLINT(tmPtr->tm_mon + 1); |
7561 day = __MKSMALLINT(tmPtr->tm_mday); |
7618 day = __MKSMALLINT(tmPtr->tm_mday); |
7562 |
7619 |
7563 yDay = __MKSMALLINT(tmPtr->tm_yday + 1); |
7620 yDay = __MKSMALLINT(tmPtr->tm_yday+1); |
7564 wDay = __MKSMALLINT(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday); |
7621 wDay = __MKSMALLINT(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday); |
7565 |
7622 |
7566 if (tmPtr->tm_isdst == 0) { |
7623 if (tmPtr->tm_isdst == 0) { |
7567 dst = false; |
7624 dst = false; |
7568 utcOffset = __MKINT(TIMEZONE(tmPtr)); |
7625 utcOffset = __MKINT(TIMEZONE(tmPtr)); |
7574 utcOffset = __MKINT(TIMEZONE(tmPtr) + 3600); |
7631 utcOffset = __MKINT(TIMEZONE(tmPtr) + 3600); |
7575 #endif |
7632 #endif |
7576 } |
7633 } |
7577 %}. |
7634 %}. |
7578 "I would love to have SELF-like inline objects ..." |
7635 "I would love to have SELF-like inline objects ..." |
7579 ret := Array new:11. |
7636 timeArray at:1 put:year. |
7580 ret at:1 put:year. |
7637 timeArray at:2 put:month. |
7581 ret at:2 put:month. |
7638 timeArray at:3 put:day. |
7582 ret at:3 put:day. |
7639 timeArray at:4 put:hours. |
7583 ret at:4 put:hours. |
7640 timeArray at:5 put:minutes. |
7584 ret at:5 put:minutes. |
7641 timeArray at:6 put:seconds. |
7585 ret at:6 put:seconds. |
7642 timeArray at:7 put:utcOffset. |
7586 ret at:7 put:utcOffset. |
7643 timeArray at:8 put:dst. |
7587 ret at:8 put:dst. |
7644 timeArray at:9 put:nil. |
7588 ret at:9 put:millis. |
7645 timeArray at:10 put:yDay. |
7589 ret at:10 put:yDay. |
7646 timeArray at:11 put:wDay. |
7590 ret at:11 put:wDay. |
7647 ^ timeArray |
7591 ^ ret |
7648 |
7592 |
7649 " |
7593 " |
7650 OperatingSystem fillTimeAndDateFromSeconds:0 into:(Array new:11) |
7594 OperatingSystem computeUTCTimeAndDateFrom:0 |
|
7595 " |
|
7596 ! |
|
7597 |
|
7598 computeUTCTimePartsOf:osTime for:aBlock |
|
7599 "compute hours, minutes, seconds and milliseconds from the osTime |
|
7600 and evaluate the argument, a 4-arg block with these. |
|
7601 Conversion is to UTC." |
|
7602 |
|
7603 |hours minutes seconds millis osSeconds| |
|
7604 |
|
7605 osSeconds := osTime // 1000. |
|
7606 millis := osTime \\ 1000. |
|
7607 %{ |
|
7608 struct tm *tmPtr; |
|
7609 long t; |
|
7610 |
|
7611 t = __longIntVal(osSeconds); |
|
7612 |
|
7613 tmPtr = gmtime(&t); |
|
7614 hours = __MKSMALLINT(tmPtr->tm_hour); |
|
7615 minutes = __MKSMALLINT(tmPtr->tm_min); |
|
7616 seconds = __MKSMALLINT(tmPtr->tm_sec); |
|
7617 %}. |
|
7618 aBlock value:hours value:minutes value:seconds value:millis |
|
7619 |
|
7620 " |
|
7621 OperatingSystem computeUTCTimePartsOf:100 for:[:h :m :s :milli | |
|
7622 h printCR. m printCR. s printCR. milli printCR |
|
7623 ] |
|
7624 " |
7651 " |
7625 ! |
7652 ! |
7626 |
7653 |
7627 getMicrosecondTime |
7654 getMicrosecondTime |
7628 "This returns the microsecond timers value - if available. |
7655 "This returns the microsecond timers value - if available. |
7908 "{ Pragma: +optSpace }" |
7936 "{ Pragma: +optSpace }" |
7909 |
7937 |
7910 "cease ANY action for some time. This suspends the whole smalltalk |
7938 "cease ANY action for some time. This suspends the whole smalltalk |
7911 (unix-) process for some time if running threadless; |
7939 (unix-) process for some time if running threadless; |
7912 if running with threads (which is the default), this will |
7940 if running with threads (which is the default), this will |
7913 only block until the nbext clock tick and return with the next |
7941 only block until the next clock tick and return with the next |
7914 timer interrupt. |
7942 timer interrupt. |
7915 Use either OperatingSystem>>millisecondDelay: (which makes all |
7943 Use either OperatingSystem>>millisecondDelay: (which makes all |
7916 threads sleep, but handles interrupts) or use a Delay (which makes |
7944 threads sleep, but handles interrupts) or use a Delay (which makes |
7917 only the calling thread sleep)." |
7945 only the calling thread sleep)." |
7918 |
7946 |