From 54818da7e5d307320e58e36206b71ae000a800a8 Mon Sep 17 00:00:00 2001 From: Sven Van Caekenberghe Date: Fri, 22 Sep 2023 14:19:24 +0200 Subject: [PATCH] Marking several --- .../ZTimestamp-Core/ZTimestamp.class.st | 14 ++++++ .../ZTimestamp-Core/ZTimestampFormat.class.st | 46 +++++++++++++++++++ repository/ZTimestamp-Core/ZTimezone.class.st | 13 +++++- .../ZTimestamp-Tests/ZTimestampTests.class.st | 39 ++++++++++++---- 4 files changed, 102 insertions(+), 10 deletions(-) diff --git a/repository/ZTimestamp-Core/ZTimestamp.class.st b/repository/ZTimestamp-Core/ZTimestamp.class.st index e7a531b..a585407 100644 --- a/repository/ZTimestamp-Core/ZTimestamp.class.st +++ b/repository/ZTimestamp-Core/ZTimestamp.class.st @@ -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" + + + ^ self now ] @@ -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" + + ^ self zero ] @@ -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" + + ^ self fromClockNanoseconds: self clockNanoseconds ] @@ -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)." + + ^ self fromClockNanoseconds: Time totalSeconds * 1e9 ] @@ -305,6 +315,8 @@ ZTimestamp class >> today [ ZTimestamp class >> unixEpoch [ "Return the Unix or POSIX epoch as a ZTimestamp" + + ^ UnixEpoch ifNil: [ UnixEpoch := self year: 1970 month: 1 day: 1 ] ] @@ -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" + + ^ Zero ifNil: [ Zero := self new jdn: 0 ns: 0 ] diff --git a/repository/ZTimestamp-Core/ZTimestampFormat.class.st b/repository/ZTimestamp-Core/ZTimestampFormat.class.st index 8e388aa..fec307a 100644 --- a/repository/ZTimestamp-Core/ZTimestampFormat.class.st +++ b/repository/ZTimestamp-Core/ZTimestampFormat.class.st @@ -77,6 +77,8 @@ ZTimestampFormat class >> ansiC [ "WeekdayAbbreviated MonthNameAbbreviated DayInMonth HH:MM:SS Year" "ZTimestampFormat ansiC format: ZTimestamp now" + + ^ self fromString: 'Sat Feb _3 16:05:06 2001' ] @@ -86,6 +88,8 @@ ZTimestampFormat class >> clock [ "HH:MM" "ZTimestampFormat clock format: ZTimestamp now" "ZTimestampFormat clock format: Time now" + + ^ self fromString: '16:05' ] @@ -96,6 +100,8 @@ ZTimestampFormat class >> euDate [ "DD/MM/YYYY" "ZTimestampFormat euDate format: ZTimestamp today" "ZTimestampFormat euDate format: Date today" + + ^ self fromString: '03/02/2001' ] @@ -183,6 +189,8 @@ ZTimestampFormat class >> iso [ "ZTimestampFormat iso format: ZTimestamp now" "ZTimestampFormat iso format: DateAndTime now" + + ^ self fromString: '2001-02-03T16:05:06Z' ] @@ -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" + + ^ self fromString: '20010203T160506' ] @@ -200,16 +210,32 @@ ZTimestampFormat class >> isoDate [ "ISO date format" "YYYY/MM/DD" "ZTimestampFormat isoDate format: ZTimestamp now" + + ^ 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" + + + + ^ 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" + + ^ self fromString: '2001-02-03T16:05:06+00:00' ] @@ -220,6 +246,8 @@ ZTimestampFormat class >> kitchen [ "HH:MM" "ZTimestampFormat kitchen format: ZTimestamp now" "ZTimestampFormat kitchen format: Time now" + + ^ self fromString: '04:05PM' ] @@ -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." + + ^ ZTimestamp year: 2001 month: 2 day: 3 hour: 4 minute: 5 second: 6 ] @@ -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." + + ^ ZTimestamp year: 2001 month: 2 day: 3 hour: 16 minute: 5 second: 6 ] { #category : #accessing } ZTimestampFormat class >> rfc3339 [ + "RFC3339 based layout" + + + ^ self iso ] @@ -251,6 +287,8 @@ ZTimestampFormat class >> rfc822 [ "DayInMonth MonthNameAbbreviated Year2Digits HH:MM TimezoneAbbreviated" "ZTimestampFormat rfc822 format: ZTimestamp now" + + ^ self fromString: '03 Feb 01 16:05 UTC' ] @@ -259,6 +297,8 @@ ZTimestampFormat class >> rfc850 [ "RFC 850 usenet format" "WeekdayName, DayInMonth-MonthNameAbbreviated-Year2Digits HH:MM TimezoneAbbreviated" "ZTimestampFormat rfc850 format: ZTimestamp now" + + ^ self fromString: 'Saturday, 03-Feb-01 16:05:06 UTC' ] @@ -269,6 +309,8 @@ ZTimestampFormat class >> unixDate [ "WeekdayNameAbbreviated MonthNameAbbreviated DayInMonth HH:MM:SS TimezoneAbbreviated Year" "ZTimestampFormat unixDate format: ZTimestamp now" + + ^ self fromString: 'Sat Feb _3 16:05:06 UTC 2001' ] @@ -278,6 +320,8 @@ ZTimestampFormat class >> usDate [ "MM/DD/YYYY" "ZTimestampFormat usDate format: ZTimestamp today" "ZTimestampFormat usDate format: Date today" + + ^ self fromString: '02/03/2001' ] @@ -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" + + ^ self fromString: 'Saturday, 03-February-2001 04:05:06 PM (+00:00)' ] diff --git a/repository/ZTimestamp-Core/ZTimezone.class.st b/repository/ZTimestamp-Core/ZTimezone.class.st index 334df79..99789bb 100644 --- a/repository/ZTimestamp-Core/ZTimezone.class.st +++ b/repository/ZTimestamp-Core/ZTimezone.class.st @@ -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 } @@ -192,6 +192,15 @@ ZTimezone class >> errorCannotUseDefaultZoneInfoLocation [ 'please specify a location using #zoneInfoLocation:' ] +{ #category : #acccessing } +ZTimezone class >> europeBrussels [ + "Return the timezone Europe/Brussels" + + + + ^ self id: 'Europe/Brussels' +] + { #category : #acccessing } ZTimezone class >> fallbackZoneinfoDatasetURL [ "The URL to the ZIP archive zoneinfo.zip which is offered as a fallback for @@ -248,6 +257,8 @@ ZTimezone class >> fromStream: in [ ZTimezone class >> gmt [ "Return the special GMT timezone, also known as UTC or Zulu" + + ^ self timezones at: #GMT ifAbsentPut: [ self createGMT ] ] diff --git a/repository/ZTimestamp-Tests/ZTimestampTests.class.st b/repository/ZTimestamp-Tests/ZTimestampTests.class.st index 436af46..93c8cbe 100644 --- a/repository/ZTimestamp-Tests/ZTimestampTests.class.st +++ b/repository/ZTimestamp-Tests/ZTimestampTests.class.st @@ -7,6 +7,33 @@ Class { #category : #'ZTimestamp-Tests' } +{ #category : #accessing } +ZTimestampTests class >> lunarLanding [ + "First manned lunar landing, Apollo 11, Mare Tranquillitatis" + + + + ^ ZTimestamp fromString: '1969-07-20T20:17:40Z' +] + +{ #category : #accessing } +ZTimestampTests class >> marsLanding [ + "First unmanned soft Mars landing, Viking 1, Chryse Planitia" + + + + ^ ZTimestamp fromString: '1979-07-20T11:53:06Z' +] + +{ #category : #accessing } +ZTimestampTests class >> unixTimeBillenium [ + "1 billion seconds since the Unix Epoch" + + + + ^ ZTimestamp fromString: '2001-09-09T01:46:40Z'. +] + { #category : #asserting } ZTimestampTests >> assertInvariants: timestamp [ self assert: (timestamp isKindOf: ZTimestamp). @@ -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 } @@ -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 ]