TimePeriod.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 22875 a389cb27c2fb
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22875
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:libbasic' }"
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: Smalltalk }"
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
Object subclass:#TimePeriod
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:'startTime endTime'
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	category:'Magnitude-Time'
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
!TimePeriod class methodsFor:'documentation'!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
documentation
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
"
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
    This class represents time periods defined by start and endtime.
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
    It will be as a representation of ISO8601 timeperiods.
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
"
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
examples
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
"
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
                                                                [exBegin]
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
     |p|
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
     p := TimePeriod startTime:(Date today) endTime:(Date tomorrow).
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
     p duration 
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
                                                                [exEnd]
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
                                                                [exBegin]
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
     |p|
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
     p := TimePeriod startTime:(Time now) endTime:(Date tomorrow).
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
     p duration 
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
                                                                [exEnd]
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
                                                                [exBegin]
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
     |p|
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
     p := TimePeriod startTime:(Timestamp now) endTime:(Timestamp fromString:'2050-01-01').
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
     p duration
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
                                                                [exEnd]
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
! !
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
!TimePeriod class methodsFor:'instance creation'!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
startTime:startTimeArg endTime:endTimeArg 
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    ^ self new startTime:startTimeArg endTime:endTimeArg 
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
! !
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
!TimePeriod methodsFor:'accessing'!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
endTime
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    ^ endTime
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
endTime:aTimeOrDate
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    endTime := aTimeOrDate asTimestamp.
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
startTime
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    ^ startTime
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
startTime:aTimeOrDate
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    startTime := aTimeOrDate asTimestamp.
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
startTime:startTimeArg endTime:endTimeArg 
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    startTime := startTimeArg asTimestamp.
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    endTime := endTimeArg asTimestamp.
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
! !
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
!TimePeriod methodsFor:'queries'!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
duration
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    "return the difference between end- and starttime"
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    ^ endTime - startTime
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
     (TimePeriod startTime:(Date today) endTime:(Date tomorrow)) duration   -> 1d
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
     (TimePeriod startTime:(Time now) endTime:(Date tomorrow)) duration     -> rest duration till tomorrow
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
     (TimePeriod startTime:(Timestamp now) endTime:(Timestamp fromString:'2050-01-01')) duration
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    "
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
! !
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
!TimePeriod class methodsFor:'documentation'!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
version
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    ^ '$Header$'
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
!
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
version_CVS
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    ^ '$Header$'
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
! !
a389cb27c2fb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95