Skip to content

Commit

Permalink
Marking several <gtExamples>
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvc committed Sep 22, 2023
1 parent f6d93fe commit 54818da
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 10 deletions.
14 changes: 14 additions & 0 deletions repository/ZTimestamp-Core/ZTimestamp.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ ZTimestamp class >> clockPrecision [

{ #category : #'instance creation' }
ZTimestamp class >> current [
"Create and return a new ZTimestamp equal to the current system time"

<gtExample>

^ self now
]

Expand All @@ -95,6 +99,8 @@ ZTimestamp class >> dateError: message [
ZTimestamp class >> epoch [
"Return the epoch of my instances, the point in time from which they start counting, as an instance"

<gtExample>

^ self zero
]

Expand Down Expand Up @@ -175,6 +181,8 @@ ZTimestamp class >> jdnFromYear: year month: month day: day [
ZTimestamp class >> now [
"Create and return a new ZTimestamp equal to the current system time"

<gtExample>

^ self fromClockNanoseconds: self clockNanoseconds
]

Expand All @@ -184,6 +192,8 @@ ZTimestamp class >> nowTruncated [
immediately truncated to whole seconds, thus containing no fractional seconds.
This is equivalent but more efficient than (self now truncated)."

<gtExample>

^ self fromClockNanoseconds: Time totalSeconds * 1e9
]

Expand Down Expand Up @@ -305,6 +315,8 @@ ZTimestamp class >> today [
ZTimestamp class >> unixEpoch [
"Return the Unix or POSIX epoch as a ZTimestamp"

<gtExample>

^ UnixEpoch
ifNil: [ UnixEpoch := self year: 1970 month: 1 day: 1 ]
]
Expand Down Expand Up @@ -407,6 +419,8 @@ ZTimestamp class >> year: year month: month day: day hour: hour minute: minute s
{ #category : #accessing }
ZTimestamp class >> zero [
"Return my zero instance, the point in time from which we start counting, see #epoch"

<gtExample>

^ Zero
ifNil: [ Zero := self new jdn: 0 ns: 0 ]
Expand Down
46 changes: 46 additions & 0 deletions repository/ZTimestamp-Core/ZTimestampFormat.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ ZTimestampFormat class >> ansiC [
"WeekdayAbbreviated MonthNameAbbreviated DayInMonth HH:MM:SS Year"
"ZTimestampFormat ansiC format: ZTimestamp now"

<gtExample>

^ self fromString: 'Sat Feb _3 16:05:06 2001'
]

Expand All @@ -86,6 +88,8 @@ ZTimestampFormat class >> clock [
"HH:MM"
"ZTimestampFormat clock format: ZTimestamp now"
"ZTimestampFormat clock format: Time now"

<gtExample>

^ self fromString: '16:05'
]
Expand All @@ -96,6 +100,8 @@ ZTimestampFormat class >> euDate [
"DD/MM/YYYY"
"ZTimestampFormat euDate format: ZTimestamp today"
"ZTimestampFormat euDate format: Date today"

<gtExample>

^ self fromString: '03/02/2001'
]
Expand Down Expand Up @@ -183,6 +189,8 @@ ZTimestampFormat class >> iso [
"ZTimestampFormat iso format: ZTimestamp now"
"ZTimestampFormat iso format: DateAndTime now"

<gtExample>

^ self fromString: '2001-02-03T16:05:06Z'
]

Expand All @@ -191,6 +199,8 @@ ZTimestampFormat class >> isoCompact [
"The standard ISO 8601 date/time format with minimal separators and implied timezone UTC"
"YYYYMMDDTHHMMSS"
"ZTimestampFormat isoCompact format: ZTimestamp now"

<gtExample>

^ self fromString: '20010203T160506'
]
Expand All @@ -200,16 +210,32 @@ ZTimestampFormat class >> isoDate [
"ISO date format"
"YYYY/MM/DD"
"ZTimestampFormat isoDate format: ZTimestamp now"

<gtExample>

^ self fromString: '2001/02/03'
]

{ #category : #accessing }
ZTimestampFormat class >> isoNanoTZ [
"The standard ISO 8601 date/time format with separators, nanosecond precision and full timezone offset"
"YYYY-MM-DDTHH:MM:SS.NNNNNNNNN+ZZ:zz"
"ZTimestampFormat isoTZ format: ZTimestamp now"
"ZTimestampFormat isoTZ format: DateAndTime now"

<gtExample>

^ self fromString: '2001-02-03T16:05:06.7+00:00'
]

{ #category : #accessing }
ZTimestampFormat class >> isoTZ [
"The standard ISO 8601 date/time format with separators with full timezone offset"
"YYYY-MM-DDTHH:MM:SS+ZZ:zz"
"ZTimestampFormat isoTZ format: ZTimestamp now"
"ZTimestampFormat isoTZ format: DateAndTime now"

<gtExample>

^ self fromString: '2001-02-03T16:05:06+00:00'
]
Expand All @@ -220,6 +246,8 @@ ZTimestampFormat class >> kitchen [
"HH:MM"
"ZTimestampFormat kitchen format: ZTimestamp now"
"ZTimestampFormat kitchen format: Time now"

<gtExample>

^ self fromString: '04:05PM'
]
Expand All @@ -228,6 +256,8 @@ ZTimestampFormat class >> kitchen [
ZTimestampFormat class >> reference12 [
"The ZTimestamp instance used as a reference for specifying a format by example.
The possible components are numbered from largest to smallest unit."

<gtExample>

^ ZTimestamp year: 2001 month: 2 day: 3 hour: 4 minute: 5 second: 6
]
Expand All @@ -236,12 +266,18 @@ ZTimestampFormat class >> reference12 [
ZTimestampFormat class >> reference24 [
"The ZTimestamp instance used as a reference for specifying a format by example.
The possible components are numbered from largest to smallest unit."

<gtExample>

^ ZTimestamp year: 2001 month: 2 day: 3 hour: 16 minute: 5 second: 6
]

{ #category : #accessing }
ZTimestampFormat class >> rfc3339 [
"RFC3339 based layout"

<gtExample>

^ self iso
]

Expand All @@ -251,6 +287,8 @@ ZTimestampFormat class >> rfc822 [
"DayInMonth MonthNameAbbreviated Year2Digits HH:MM TimezoneAbbreviated"
"ZTimestampFormat rfc822 format: ZTimestamp now"

<gtExample>

^ self fromString: '03 Feb 01 16:05 UTC'
]

Expand All @@ -259,6 +297,8 @@ ZTimestampFormat class >> rfc850 [
"RFC 850 usenet format"
"WeekdayName, DayInMonth-MonthNameAbbreviated-Year2Digits HH:MM TimezoneAbbreviated"
"ZTimestampFormat rfc850 format: ZTimestamp now"

<gtExample>

^ self fromString: 'Saturday, 03-Feb-01 16:05:06 UTC'
]
Expand All @@ -269,6 +309,8 @@ ZTimestampFormat class >> unixDate [
"WeekdayNameAbbreviated MonthNameAbbreviated DayInMonth HH:MM:SS TimezoneAbbreviated Year"
"ZTimestampFormat unixDate format: ZTimestamp now"

<gtExample>

^ self fromString: 'Sat Feb _3 16:05:06 UTC 2001'
]

Expand All @@ -278,6 +320,8 @@ ZTimestampFormat class >> usDate [
"MM/DD/YYYY"
"ZTimestampFormat usDate format: ZTimestamp today"
"ZTimestampFormat usDate format: Date today"

<gtExample>

^ self fromString: '02/03/2001'
]
Expand All @@ -288,6 +332,8 @@ ZTimestampFormat class >> verbose [
"WeekdayName, DayInMonth-MonthName-Year HH:MM:SS DayPart (+ZZ:zz"
"ZTimestampFormat verbose format: ZTimestamp now"
"ZTimestampFormat verbose format: DateAndTime now"

<gtExample>

^ self fromString: 'Saturday, 03-February-2001 04:05:06 PM (+00:00)'
]
Expand Down
13 changes: 12 additions & 1 deletion repository/ZTimestamp-Core/ZTimezone.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ZTimezone class >> current: identifierOrTimezone [
ZTimezone class >> defaultZoneCET [
"The timezone identifiers in #centralEuropeanAliases resolve to this actual timezone"

^ self id: 'Europe/Brussels'
^ self europeBrussels
]

{ #category : #acccessing }
Expand Down Expand Up @@ -192,6 +192,15 @@ ZTimezone class >> errorCannotUseDefaultZoneInfoLocation [
'please specify a location using #zoneInfoLocation:'
]

{ #category : #acccessing }
ZTimezone class >> europeBrussels [
"Return the timezone Europe/Brussels"

<gtExample>

^ self id: 'Europe/Brussels'
]

{ #category : #acccessing }
ZTimezone class >> fallbackZoneinfoDatasetURL [
"The URL to the ZIP archive zoneinfo.zip which is offered as a fallback for
Expand Down Expand Up @@ -248,6 +257,8 @@ ZTimezone class >> fromStream: in [
ZTimezone class >> gmt [
"Return the special GMT timezone, also known as UTC or Zulu"

<gtExample>

^ self timezones at: #GMT ifAbsentPut: [ self createGMT ]
]

Expand Down
39 changes: 30 additions & 9 deletions repository/ZTimestamp-Tests/ZTimestampTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ Class {
#category : #'ZTimestamp-Tests'
}

{ #category : #accessing }
ZTimestampTests class >> lunarLanding [
"First manned lunar landing, Apollo 11, Mare Tranquillitatis"

<gtExample>

^ ZTimestamp fromString: '1969-07-20T20:17:40Z'
]

{ #category : #accessing }
ZTimestampTests class >> marsLanding [
"First unmanned soft Mars landing, Viking 1, Chryse Planitia"

<gtExample>

^ ZTimestamp fromString: '1979-07-20T11:53:06Z'
]

{ #category : #accessing }
ZTimestampTests class >> unixTimeBillenium [
"1 billion seconds since the Unix Epoch"

<gtExample>

^ ZTimestamp fromString: '2001-09-09T01:46:40Z'.
]

{ #category : #asserting }
ZTimestampTests >> assertInvariants: timestamp [
self assert: (timestamp isKindOf: ZTimestamp).
Expand Down Expand Up @@ -35,16 +62,12 @@ ZTimestampTests >> assertTimestamp: timestamp equalsTimestamp: reference [

{ #category : #accessing }
ZTimestampTests >> lunarLanding [
"First lunar landing, Apollo 11, Mare Tranquillitatis"

^ ZTimestamp fromString: '1969-07-20T20:17:40Z'
^ self class lunarLanding
]

{ #category : #accessing }
ZTimestampTests >> marsLanding [
"First soft Mars landing, Viking 1, Chryse Planitia"

^ ZTimestamp fromString: '1979-07-20T11:53:06Z'
^ self class marsLanding
]

{ #category : #testing }
Expand Down Expand Up @@ -476,7 +499,5 @@ ZTimestampTests >> testZTimestampFormatting [

{ #category : #accessing }
ZTimestampTests >> unixTimeBillenium [
"1 billion seconds since the Unix Epoch"

^ ZTimestamp fromString: '2001-09-09T01:46:40Z'.
^ self class unixTimeBillenium
]

0 comments on commit 54818da

Please sign in to comment.