AbstractTime.st
changeset 3476 f2ebb76a952d
parent 2310 2cb1366e0eb3
child 4649 3eaf75dd8973
equal deleted inserted replaced
3475:e8519ba62840 3476:f2ebb76a952d
   228      |t1 t2|
   228      |t1 t2|
   229 
   229 
   230      t1 := AbsoluteTime now.
   230      t1 := AbsoluteTime now.
   231      (Delay forSeconds:5) wait.
   231      (Delay forSeconds:5) wait.
   232      t2 := AbsoluteTime now.
   232      t2 := AbsoluteTime now.
   233      'seconds passed: ' print. (t2 - t1) printNL.
   233      Transcript showCR:('seconds passed: ' , (t2 - t1) printString).
   234     "
   234     "
   235 !
   235 !
   236 
   236 
   237 addHours:numberOfHours
   237 addHours:numberOfHours
   238     "return a new instance of myself, numberOfHours afterwards."
   238     "return a new instance of myself, numberOfHours afterwards."
   241 
   241 
   242     "
   242     "
   243      |t|
   243      |t|
   244 
   244 
   245      t := AbsoluteTime now.
   245      t := AbsoluteTime now.
   246      t printNL.
   246      Transcript showCR:t.
   247      (t addHours:50) printNL
   247      t printNL.
   248     "
   248      Transcript showCR:(t addHours:12).
       
   249     "
       
   250 
       
   251     "
       
   252      |t|
       
   253 
       
   254      t := Time now.
       
   255      Transcript showCR:t.
       
   256      t printNL.
       
   257      Transcript showCR:(t addHours:12).
       
   258     "
       
   259 
   249 !
   260 !
   250 
   261 
   251 addMinutes:numberOfMinutes
   262 addMinutes:numberOfMinutes
   252     "return a new instance of myself, numberOfMinutes afterwards."
   263     "return a new instance of myself, numberOfMinutes afterwards."
   253 
   264 
   254     ^ self addSeconds:(numberOfMinutes * 60)
   265     ^ self addSeconds:(numberOfMinutes * 60)
   255 
   266 
   256     "
   267     "
   257      |t|
   268      |t|
   258 
   269 
   259      t := AbsoluteTime now. t printNL. (t addMinutes:50) printNL
   270      t := AbsoluteTime now.
   260 
   271      Transcript showCR:t.
   261      t := Time now. t printNL. (t addMinutes:50) printNL
   272      t printNL.
       
   273      Transcript showCR:(t addMinutes:60).
       
   274     "
       
   275 
       
   276     "
       
   277      |t|
       
   278 
       
   279      t := Time now.
       
   280      Transcript showCR:t.
       
   281      t printNL.
       
   282      Transcript showCR:(t addMinutes:60).
   262     "
   283     "
   263 !
   284 !
   264 
   285 
   265 addSeconds:numberOfSeconds
   286 addSeconds:numberOfSeconds
   266     "return a new instance of myself, numberOfSeconds afterwards."
   287     "return a new instance of myself, numberOfSeconds afterwards."
   267 
   288 
   268     ^ self species basicNew setSeconds:(self getSeconds + numberOfSeconds)
   289     ^ self species basicNew 
   269 
   290         setMilliseconds:(self getMilliseconds + (numberOfSeconds * 1000))
   270     "
   291 
   271      |t|
   292     "
   272 
   293      |t|
   273      t := AbsoluteTime now. t printNL. (t addSeconds:50) printNL.
   294 
   274 
   295      t := AbsoluteTime now.
   275      t := Time now. t printNL. (t addSeconds:50) printNL
   296      Transcript showCR:t.
   276     "
   297      t printNL.
       
   298      Transcript showCR:(t addSeconds:60).
       
   299     "
       
   300 
       
   301     "
       
   302      |t|
       
   303 
       
   304      t := Time now.
       
   305      Transcript showCR:t.
       
   306      t printNL.
       
   307      Transcript showCR:(t addSeconds:60).
       
   308     "
       
   309 
   277 !
   310 !
   278 
   311 
   279 addTime:timeAmount
   312 addTime:timeAmount
   280     "return a new instance of myself, timeAmount seconds afterwards.
   313     "return a new instance of myself, timeAmount seconds afterwards.
   281      AddTime is a bad name - it does not add a time, but expects
   314      Provided for ST-80 compatibility.
   282      a number. Use any of addSeconds/addHours etc."
   315      WARNING:
   283 
   316         AddTime is a bad name - it does not add a time, but expects
   284     ^ self species basicNew setSeconds:(self getSeconds + timeAmount)
   317         a numberOfSeconds as argument. 
       
   318         Use any of addSeconds/addHours etc. to make things clear"
       
   319 
       
   320     ^ self addSeconds:timeAmount
   285 !
   321 !
   286 
   322 
   287 subtractHours:numberOfHours
   323 subtractHours:numberOfHours
   288     "return a new instance of myself, numberOfHours before."
   324     "return a new instance of myself, numberOfHours before."
   289 
   325 
   291 
   327 
   292     "
   328     "
   293      |t|
   329      |t|
   294 
   330 
   295      t := AbsoluteTime now.
   331      t := AbsoluteTime now.
   296      t printNL.
   332      Transcript showCR:t.
   297      (t subtractHours:50) printNL
   333      t printNL.
       
   334      Transcript showCR:(t subtractHours:12).
       
   335     "
       
   336 
       
   337     "
       
   338      |t|
       
   339 
       
   340      t := Time now.
       
   341      Transcript showCR:t.
       
   342      t printNL.
       
   343      Transcript showCR:(t subtractHours:12).
   298     "
   344     "
   299 !
   345 !
   300 
   346 
   301 subtractMinutes:numberOfMinutes
   347 subtractMinutes:numberOfMinutes
   302     "return a new instance of myself, numberOfMinutes before."
   348     "return a new instance of myself, numberOfMinutes before."
   305 
   351 
   306     "
   352     "
   307      |t|
   353      |t|
   308 
   354 
   309      t := AbsoluteTime now.
   355      t := AbsoluteTime now.
   310      t printNL.
   356      Transcript showCR:t.
   311      (t subtractMinutes:50) printNL
   357      t printNL.
       
   358      Transcript showCR:(t subtractMinutes:60).
       
   359     "
       
   360 
       
   361     "
       
   362      |t|
       
   363 
       
   364      t := Time now.
       
   365      Transcript showCR:t.
       
   366      t printNL.
       
   367      Transcript showCR:(t subtractMinutes:60).
   312     "
   368     "
   313 !
   369 !
   314 
   370 
   315 subtractSeconds:numberOfSeconds
   371 subtractSeconds:numberOfSeconds
   316     "return a new instance of myself, numberOfSeconds before."
   372     "return a new instance of myself, numberOfSeconds before."
   317 
   373 
   318     ^ self species basicNew setSeconds:(self getSeconds - numberOfSeconds)
   374     ^ self species basicNew 
   319 
   375         setMilliseconds:(self getMilliseconds - (numberOfSeconds * 1000))
   320     "
   376 
   321      |t|
   377     "
   322 
   378      |t|
   323      t := AbsoluteTime now.
   379 
   324      t printNL.
   380      t := AbsoluteTime now.
   325      (t subtractSeconds:50) printNL
   381      Transcript showCR:t.
   326     "
   382      t printNL.
       
   383      Transcript showCR:(t subtractSeconds:60).
       
   384     "
       
   385 
       
   386     "
       
   387      |t|
       
   388 
       
   389      t := Time now.
       
   390      Transcript showCR:t.
       
   391      t printNL.
       
   392      Transcript showCR:(t subtractSeconds:60).
       
   393     "
       
   394 
   327 !
   395 !
   328 
   396 
   329 subtractTime:timeAmount
   397 subtractTime:timeAmount
   330     "return a new instance opf myself, timeAmount seconds before myself.
   398     "return a new instance of myself, timeAmount seconds before myself.
   331      SubtractTime is a bad name - it does not subtract a time, but expects
   399      Provided for ST-80 compatibility.
   332      a number. Use any of subtractSeconds/subtractHours etc."
   400      WARNING:
   333 
   401         SubtractTime is a bad name - it does not add a time, but expects
   334     ^ self species basicNew setSeconds:(self getSeconds - timeAmount)
   402         a numberOfSeconds as argument. 
       
   403         Use any of addSeconds/addHours etc. to make things clear"
       
   404 
       
   405     ^ self subtractSeconds:timeAmount
       
   406 
   335 ! !
   407 ! !
   336 
   408 
   337 !AbstractTime methodsFor:'private'!
   409 !AbstractTime methodsFor:'private'!
   338 
   410 
   339 fromOSTime:osTime
   411 fromOSTime:osTime
   381 ! !
   453 ! !
   382 
   454 
   383 !AbstractTime class methodsFor:'documentation'!
   455 !AbstractTime class methodsFor:'documentation'!
   384 
   456 
   385 version
   457 version
   386     ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.14 1997-01-29 18:01:17 stefan Exp $'
   458     ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.15 1998-05-22 10:47:19 cg Exp $'
   387 ! !
   459 ! !