Date subclass: #GregorianDate instanceVariableNames: 'mjd' classVariableNames: 'DayNames2 MonthNames2' poolDictionaries: '' category: 'GregorianDate'! GregorianDate subclass: #JapaneseDate instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'GregorianDate'! !GregorianDate methodsFor: 'computing' ! addDays: dayCount "dayCount日後の日を返す" ^self class new mjd: (self mjd + dayCount)! addWeekDays: dayCount "休日と日曜日を除く、dayCount日後の日を返す" ^self implementedBySubclass! dayIndex "何曜日かを表す数字。Dateクラスとの互換性のためにある。普通は、dayNumberを使うこと。 月曜日は1、...、土曜日は6、日曜日は7。" self dayNumber = 0 ifTrue: [^7] ifFalse: [^self dayNumber]! dayNumber "何曜日かを表す数字。 日曜日は0、月曜日は1、...、土曜日は6" ^(self mjd truncated - 4) \\ 7! dayOfYear "年の始めからの日数。1月1日は1を返す。" ^self mjd - (self class year: self year month: 1 newDay: 0) mjd! daysLeftInMonth "レシーバーの日からその月末までの日数。" | lastDay | lastDay := self class year: self year month: self month + 1 newDay: 0. ^lastDay subtractDate: self! elapsedDaysSince: aDate "Answer the number of elapsed days between the receiver and ." ^self mjd - aDate mjd! firstDayInMonth ^(self class year: self year month: self month newDay: 1) dayOfYear! previousWeekday: aName "直近のaNameを曜日名として持つ日を返す。" | dayNumber dayNumberPrev daysToSub | dayNumber := self dayNumber. dayNumberPrev := self class dayOfWeek: aName. daysToSub := dayNumber - dayNumberPrev. dayNumber <= dayNumberPrev ifTrue: [daysToSub := daysToSub + 7]. ^self subtractDays: daysToSub! subtractDate: aDate "Answer the number of days between the receiver and ." ^(self mjd - aDate mjd) asInteger! subtractDays: dayCount "Answer the date that is days before the receiver." ^self class new mjd: (self mjd - dayCount)! subtractWeekDays: dayCount "Answer the date that is days before the receiver." ^self implementedBySubclass! ! !GregorianDate methodsFor: 'testing' ! < aDate "Answer if the receiver is before ." ^self mjd < aDate mjd! <= aDate "Answer if the receiver is before or the same as ." ^self mjd <= aDate mjd! = aDate "Answer if the receiver is the same as ." ^self mjd = aDate mjd! > aDate "Answer if the receiver is after ." ^self mjd > aDate mjd! >= aDate "Answer if the receiver is the same or after ." ^aDate mjd <= self mjd! isHoliday "休日か日曜日であればtrueを、そうでなければfalseを返す。" ^self implementedBySubclass! ! !GregorianDate methodsFor: 'private' ! dateToYmdAux "Private -- 準ユリウス日から年月日を求めるための補助関数。" | jd century | jd := self class mjdToJd: self mjd. jd > 2299160 ifTrue: [ "グレゴリオ歴のとき" century := (jd + 32044.9) // 36524.25. ^jd + 32044.9 + century - (century // 4) + 0.5] ifFalse: [ "ユリウス歴のとき" ^jd + 32082.9 + 0.5]. ! index "Answer a Number which will order the receiver within its class." ^self mjd! mjd "Private -- 準ユリウス日mjd(Modified Julian Day)を返す" ^mjd! mjd: aFloat "Private -- 準ユリウス日mjd(Modified Julian Day)を設定する" mjd := aFloat! monthAux "Private -- 月を求める補助関数" ^(self dateToYmdAux + 122.1 - (365.25 * self yearAux) truncated) // 30.6001! yearAux "Private -- 年を求める補助関数" ^self dateToYmdAux // 365.25! ! !GregorianDate methodsFor: 'instance creation' ! firstDayOfMonth "レシーバーと同じ月の最初の日を返す。" ^self class year: self year month: self month newDay: 1! time "時刻を返す" | totalSeconds totalMinutes | totalSeconds := (self dayAsFloat - self day) * 86400. "1日86400秒" totalMinutes := totalSeconds // 60. ^Time hours: totalMinutes // 60 minutes: totalMinutes \\ 60 seconds: (totalSeconds \\ 60) rounded! ! !GregorianDate methodsFor: 'accessing' ! day "日を返す" ^self dayAsFloat truncated! day: anInteger "Dateクラスとの互換性のためと同じ機能" ^self mjd: anInteger! dayOfMonth ^self day! month "月を返す" ^self monthAux < 14 ifTrue: [^self monthAux - 1] ifFalse: [^self monthAux - 13]! monthIndex ^self month! year "年を返す" ^self monthAux < 14 ifTrue: [^self yearAux - 4800] ifFalse: [^self yearAux - 4799]! ! !GregorianDate methodsFor: 'converting' ! age "selfを誕生日として年齢を返す" (Date today dayOfYear < self dayOfYear) ifTrue: [^Date today year - self year - 1] "誕生日が来ていない場合" ifFalse: [^Date today year - self year] "誕生日を過ぎた場合"! asSeconds "1981年1月1日からの秒数を返す。" ^self elapsedSecondsSince: (self class year: 1981 month: 1 newDay: 1)! dayAsFloat "日を実数で返す" ^self dateToYmdAux + 122.1 - (365.25 * self yearAux) truncated - (30.6001 * self monthAux) truncated! hash "Answer the integer hash value for the receiver." ^self mjd hash! ! !GregorianDate methodsFor: 'printing' ! printOn: aStream "Append a string representing the receiver date to aStream in the form specified by the current system date format." self printOn: aStream inFormat: NationalLanguage dateFormat twoDigitYear: false.! printOn: aStream inFormat: aFormat twoDigitYear: aBoolean dateSeparator: dateSeparatorString "Append a string representing the receiver date to aStream in the form specified by aFormat and aBoolean. Use dateSeparatorString as the date separator" | field1 field2 field3 year aDay | year := self year. aBoolean ifTrue: [year := year \\ 100]. aFormat = NationalLanguageSupport dateFormatMDY ifTrue: [field1 := self monthIndex. field2 := self dayOfMonth. field3 := year] ifFalse: [aFormat = NationalLanguageSupport dateFormatDMY ifTrue: [field1 := self dayOfMonth. field2 := self monthIndex. field3 := year] ifFalse: [ "dateFormatYMD" field1 := year. field2 := self monthIndex. field3 := self dayOfMonth]]. field1 <= 9 ifTrue: [aStream nextPut: $0]. field1 printOn: aStream. aStream nextPutAll: dateSeparatorString. field2 <= 9 ifTrue: [aStream nextPut: $0]. field2 printOn: aStream. aStream nextPutAll: dateSeparatorString. field3 <= 9 ifTrue: [aStream nextPut: $0]. aDay := self dayAsFloat. aDay = aDay asInteger ifTrue: [aDay truncated printOn: aStream] ifFalse: [aDay truncated printOn: aStream. aStream nextPut: $ . self time printOn: aStream]! ! !GregorianDate class methodsFor: 'computing' ! autumnalEquinoxDate: year "秋分の日を求める。参考文献=Jean Meeus, 「Astronomical Formulae for Calculators」(3ed Ed.,Willmann-Bell,1985)" | y | y := year / 1000. ^self jdToMjd: (1721325.6978 + (365.2425055 * year) - (y * y * (0.1266890 - (0.0019401 * y))))! autumnalEquinoxDay: year "秋分の日が9月の第何日かを求める。1980年から2099年まで有効な簡易計算。参考文献=「こよみ便利帳(恒星社厚生閣)」" ^(23.2488 + (0.242194 * (year - 1980)) - ((year - 1980) // 4)) floor! daysInMonth: month forYear: year "year年month月の日数を返す。" | firstDay lastDay | firstDay := self year: year month: month newDay: 1. lastDay := self year: year month: month + 1 newDay: 0. ^(lastDay subtractDate: firstDay) + 1! daysInYear: year "year年の日数を返す。" | firstDay lastDay | firstDay := self year: year month: 1 newDay: 1. lastDay := self year: year + 1 month: 1 newDay: 1. ^lastDay subtractDate: firstDay! vernalEquinoxDate: year "春分の日を求める。参考文献=Jean Meeus, 「Astronomical Formulae for Calculators」(3ed Ed.,Willmann-Bell,1985)" | y | y := year / 1000. ^self jdToMjd: (1721139.2855 + (365.2421376 * year) + (y * y * (0.0679190 - (0.0027879 * y))))! vernalEquinoxDay: year "year年の春分の日が3月の第何日かを求める。1980年から2099年まで有効な簡易計算。参考文献=「こよみ便利帳(恒星社厚生閣)」" ^(20.8431 + (0.242194 * (year - 1980)) - ((year - 1980) // 4)) floor! ! !GregorianDate class methodsFor: 'as yet unclassified' ! COMMENT "GregorianDate-クラGregorianDateのインスタンスはグレゴリオ暦の準ユリウス日(Modified Julian Day = MJD)を表す。これに対してクラスDateはグレゴリオ暦の1901年1月1日以後の日を表す。天文計算では、紀元前4713年1月1日12時UT(Universal Time = 世界時)を第0日としたユリウス日(Julian Day = JD)を使用する。しかし、現在ではJDの桁数が多くなったため、1858年11月17日0時UTを始まりとするMJDを一般には用いる。 1582年10月4日の翌日は10月15日である。これ以前はユリウス暦をつかっていた(各国でグレゴリオ暦の採用年数は異なる)。 インスタンス変数mjdは準ユリウス日(MJD)を表す。 MJD = JD - 2400000.5 である。 Dateから継承するインスタンス変数dayは、Dateの実装がひどいため使わない。 y年m月d日のユリウス日JDは次の式で与えられる。 m > 2 ifTrue: [ yy := y + 4800. mm := m + 1] ifFalse: [ yy := y + 4799. mm := m + 13]. cc := (yy / 100) truncated. グレゴリオ歴 ifTrue: [ccc := (cc / 4) truncated - cc - 32167] ifFalse: [ ユリウス歴の場合 ccc := - 32205]. JD := (365.25 * yy) truncated + (30.6001 * mm) truncated + d + ccc - 0.5 . ユリウス日JDからy年m月d日への変換は以下の式で与えられる。 JD > 2299160 ifTrue: [ グレゴリオ歴のとき cc := ((JD + 32044.9) / 36524.25) truncated. JDJD := JD + 32044.9 + cc - (cc / 4) truncated + 0.5] ifFalse: [ ユリウス歴のとき JDJD := JD + 32082.9 + 0.5]. yy := (JDJD / 365.25) truncated. mm := ((JDJD + 122.1 - (365.25 * yy) truncated) / 30.6001) truncated. d := JDJD + 122.1 - (365.25 * yy) truncated - (30.6001 * mm) truncated. mm < 14 ifTrue: [m := mm - 1. y := yy - 4800] ifFalse: [m := mm - 13. y := yy - 4799] "! ! !GregorianDate class methodsFor: 'testing' ! isCorrectDayName: dayName "dayNameが正しい曜日名が正しければ曜日名を、正しくなければfalseを返す。" | dayNameArray | dayNameArray := self initialize; dayNames. ^(dayNameArray detect: [:each | each = dayName] ifNone: [^false])! leapYear: year "閏年なら1を、そうでなければ0を返す" (year \\ 4 = 0 and: [year \\ 100 > 0 or: [year \\ 400 = 0]]) ifTrue: [^1]. ^0! ! !GregorianDate class methodsFor: 'instance creation' ! dateAndTimeNow "「今日」を返す。時間は今。" | date | date := self today. ^self year: date year month: date month newDay: date day time: Time now! fromDays: dayCount "Dateクラスでは1901年1月1日からの日数を日付計算に使うが、GregorianDateではMJDを使う。" ^self new mjd: dayCount! fromString: dateString "日付文字列から日を求める。 今の所、'1995/3/4'と'1995-3-4'およびこれらの年が2桁という形式だけ認める。 年が2桁の場合は、現在日と同じ世紀とみなす。" | aStream year month day isDouble | aStream := (ReadStream on: dateString). year := aStream nextWord asInteger. year < 100 ifTrue: [year := year + (self today year // 100 * 100)]. month := aStream nextWord asInteger. day := aStream nextWord asInteger. ^self year: year month: month newDay: day! today "「今日」を返す。時間は0時" | systemTime | systemTime := WinSystemTime new. KernelLibrary getLocalTime: systemTime asParameter. ^systemTime asGregorianDate! todayNow "「今日」を返す。時間は今。" | date | date := self today. ^self year: date year month: date month newDay: date day time: Time now! year: year month: month newDay: day "y年m月d日の準ユリウス日mjdは次の式で与えられる。" | y m century cc date | month > 2 ifTrue: [y := year + 4800. m := month + 1] ifFalse: [y := year + 4799. m := month + 13]. century := y // 100. (self dateToYear: year month: month day: day) > 1582.78 "グレゴリオ歴施行の1582年10月15日以降か?" ifTrue: "グレゴリオ歴の場合" [cc := century // 4 - century - 32167] ifFalse: "ユリウス歴の場合" [cc := -32205]. date := self new. date mjd: (365.25 * y) truncated + (30.6001 * m) truncated + day + cc - 0.5 - self jdMinusMjd. ^date! year: year month: month newDay: day time: time "y年m月d日time時の準ユリウス日mjdは次の式で与えられる。" | date | date := (self year: year month: month newDay: day). ^date mjd: (date mjd + time toDay)! ! !GregorianDate class methodsFor: 'private' ! checkDay: dayOfMonth month: monthName year: year "GregorianDateでは、敢えて日付のチェックをしない。 '1995/3/0' asGregorianDate =1995/2/28  といった指定ができて、かえって便利である。" ^self error: 'GregorianDate don''t know '! checkDay: dayOfYear year: year "GregorianDateでは、敢えて日付のチェックをしない。 '1995/3/0' asGregorianDate =1995/2/28  といった指定ができて、かえって便利である。" ^self error: 'GregorianDate don''t know '! dateToYear: year month: month day: day "Private -- 日を年に換算する" ^year + ((month - 1) / 12.0) + ((day - 1.0) / 365.25).! isDateDelimiter "Private -- 日付形式の文字列の区切り記号'/'や'-'であるか判定する" ^self = '/' or: [self = '-']! jdMinusMjd "Private -- JDとMJDの日数の差を返す。 JDは、紀元前4713年1月1日12時UTを第0日とした日数。 MJDは、1858年11月17日0時UTを始まりとする日数。" ^2400000.5! leapYearsTo: year "Dateクラスでは、日付計算のため1901年からの閏年の数を必要とするが、GregorianDateではMJDを元に計算するため不要。" ^self error: 'GregorianDate don''t know '! newDay: dayIndex month: monthName year: year "DateクラスではAprilといった月の名前で日付計算を行うが、GregorianDateでは月を表す数字(1..12)で計算するため不要。" ^self error: 'GregorianDate don''t know '! newDay: dayIndex year: year "DateクラスではAprilといった月の名前で日付計算を行うが、GregorianDateでは月を表す数字(1..12)で計算するため不要。" ^self error: 'GregorianDate don''t know '! ! !GregorianDate class methodsFor: 'accessing' ! dayNames "曜日名のArrayをクラス変数から得る" ^DayNames2.! dayNames: anArray "曜日名のArrayをクラス変数にセットする。" DayNames2 := anArray! monthNames "月名のArrayをクラス変数から得る。" ^MonthNames2.! monthNames: anArray "月名のArrayをクラス変数にセットする" MonthNames2 := anArray! ! !GregorianDate class methodsFor: 'converting' ! jdToMjd: jd "JDをMJDに変換する" ^self new mjd: (jd - self jdMinusMjd)! mjdToJd: mjd "MJDをJDに変換する" ^mjd + self jdMinusMjd! ! !GregorianDate class methodsFor: 'displaying' ! calendarForMonth: month year: year "year年month月のカレンダーを文字列として返す。" | aDay lastDay output counter firstDayIndex index | output := WriteStream on: (String new: 200). #(0 1 2 3 4 5 6) do: [:i | output nextPutAll: (((self nameOfDay: i) asString) copyFrom: 1 to: 2)] andBetweenDo: [output space]. output cr. aDay := self year: year month: month newDay: 1. firstDayIndex := aDay dayNumber. lastDay := self year: year month: month + 1 newDay: 0. output cr. index := 0. [index < firstDayIndex] whileTrue: [output nextPutAll: ' '. index := index + 1]. counter := 1. [aDay <= lastDay] whileTrue: [aDay day < 10 ifTrue: [output space]. aDay day printOn: output. output space. aDay := aDay addDays: 1. counter := counter + 1. index := index + 1. (index \\ 7 = 0) ifTrue: [output cr]]. ^output contents! dayOfWeek: dayName "Dateクラスでは、曜日名を英語のシンボル名に決め打ちしているので、private methodを呼んで曜日名を得るように改良。" | dayNameArray result | dayNameArray := self initialize; dayNames. result := dayNameArray indexOf: (dayNameArray detect: [:each | each = dayName]). ^result - 1! nameOfDay: dayNumber "曜日を表す数字から、曜日の名前を返す。" | dayName | (dayNumber between: 0 and: 6) ifFalse: [self errorInDay]. dayName := (self initialize; dayNames) at: dayNumber + 1. dayName == nil ifTrue: [self errorInDay]. ^dayName! nameOfMonth: monthIndex "monthIndex月の名前を返す。" | monthName | (monthIndex between: 1 and: 12) ifFalse: [self errorInMonth]. monthName := (self initialize; monthNames) at: monthIndex. monthName == nil ifTrue: [self errorInMonth]. ^monthName! ! !GregorianDate class methodsFor: 'initializing' ! initialize self dayNames: #('Sun' 'Mon' 'Tue' 'Wed' 'Thr' 'Fri' 'Sat'). self monthNames: #('Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec'). ! ! !JapaneseDate methodsFor: 'accessing' ! holiday "レシーバーの年の休日をSortedCollectionで返す。" ^self class holidayAt: self year! ! !JapaneseDate methodsFor: 'testing' ! holidaysBetween: aDate "レシーバーとaDateの間の休日をSortedCollectionとして返す。レシーバーとaDateが休日でも、それらは含まない。" | holidays | holidays := self holidaysBetweenAux: aDate. ^holidays select: [:holiday | holiday > (self min: aDate) and: [holiday < (self max: aDate)]]! isDayOff "休日かまたは日曜日であればtrueを、そうでなければfalseを返す。" ^self isSunday or: [self isHoliday]! isHoliday "休日か否かを返す" ^(self class holidayAt: self year) includes: self! isSaturday "土曜日か否かを返す" ^self dayNumber = 6! isSunday "日曜日か否かを返す" ^self dayNumber = 0! ! !JapaneseDate methodsFor: 'converting' ! toJST "UT(Universal Time = 世界時)をJST(日本標準時)に変換する" "0.375 day = 9 hours" ^self addDays: 0.375! toUT "JST(日本標準時)をUT(Universal Time = 世界時)に変換する" "0.375 day = 9 hours" ^self subtractDays: 0.375! toUT: aJST "JST(日本標準時)をUT(Universal Time = 世界時)に変換する" "0.375 day = 9 hours" ^aJST subtractDays: 0.375! ! !JapaneseDate methodsFor: 'private' ! holidaysBetweenAux: aDate "Private -- レシーバーの年からaDateの年の間の全休日をSortedCollectionとして返す" | holidays | holidays := OrderedCollection new. (self year min: aDate year) to: (self year max: aDate year) do: [:year | holidays addAll: (self class holidayAt: year)]. ^holidays asSortedCollection! ! !JapaneseDate methodsFor: 'computing' ! addWeekDays: dayCount "休日と日曜日を除く、dayCount日後の日を返す" | beforeDate sign | sign := dayCount negated sign. beforeDate := self subtractWeekDaysAux: dayCount negated. beforeDate isDayOff ifTrue: [^beforeDate subtractWeekDaysAux: sign] ifFalse: [^beforeDate]! occurrencesOfDayOffsBetween: aDate "レシーバーとaDateの間の休日数(休日+日曜日)を返す。aDateが休日であればそれを含む休日数を返す。" | holidays sundays | self = aDate ifTrue: [^0]. sundays := self occurrencesOfSundaysBetween: aDate. holidays := self holidaysBetween: aDate. aDate isDayOff ifTrue: [holidays add: aDate]. ^sundays + (holidays inject: 0 into: [:count :holiday | count + (holiday isSunday ifTrue: [0] ifFalse: [1])]).! occurrencesOfHolidaysBetween: aDate "レシーバーとaDateの間の休日数(休日)を返す。aDateが休日であればそれを含む休日数を返す。" | holidayAsSunday holidays | self = aDate ifTrue: [^0]. holidays := self holidaysBetween: aDate. aDate isHoliday ifTrue: [^holidays size + 1] ifFalse: [^holidays size]! occurrencesOfSundaysBetween: aDate "レシーバーとaDateの間の日曜日の日数を返す。aDateまたはレシーバーが日曜日であればそれを含む日曜日数を返す。" |days min | min := self min: aDate. days := (self max: aDate) subtractDate: min. ^(min dayIndex + days) // 7! subtractWeekDate: aDate "レシーバーとaDateの間に休日を除き何日あるか返す。" | sign days absDays | days := (self subtractDate: aDate). sign := days sign. absDays := days abs - (self occurrencesOfDayOffsBetween: aDate). ^absDays * sign! subtractWeekDays: dayCount "レシーバーの(休日を除く)日数前の日を返す。" | beforeDate sign | sign := dayCount sign. beforeDate := self subtractWeekDaysAux: dayCount. beforeDate isDayOff ifTrue: [^beforeDate subtractWeekDaysAux: sign] ifFalse: [^beforeDate]! subtractWeekDaysAux: dayCount "レシーバーの(休日を除く)日数前の日を返す。" | beforeDate beforeDate2 sign count | sign := dayCount sign. beforeDate := self subtractDays: dayCount. count := (self occurrencesOfDayOffsBetween: beforeDate) * sign. beforeDate2 := beforeDate. [count abs > 0] whileTrue: [beforeDate2 := beforeDate subtractDays: count. count := (beforeDate occurrencesOfDayOffsBetween: beforeDate2) * sign. beforeDate := beforeDate2. ]. ^beforeDate2! ! !JapaneseDate class methodsFor: 'instance creation' ! today "「今日」を返す。時間は0時" | systemTime | systemTime := WinSystemTime new. KernelLibrary getLocalTime: systemTime asParameter. ^systemTime asJapaneseDate! ! !JapaneseDate class methodsFor: 'converting' ! autumnalEquinoxDate: year "日本での秋分の日を求める。参考文献=Jean Meeus, 「Astronomical Formulae for Calculators」(3ed Ed.,Willmann-Bell,1985)" ^(super autumnalEquinoxDate: year) toJST! vernalEquinoxDate: year "日本での春分の日を求める。参考文献=Jean Meeus, 「Astronomical Formulae for Calculators」(3ed Ed.,Willmann-Bell,1985)" ^(super vernalEquinoxDate: year) toJST! ! !JapaneseDate class methodsFor: 'displaying' ! calendarForMonth: month year: year "year年month月のカレンダーを作る" | aDay lastDay output counter firstDayIndex index | output := WriteStream on: (String new: 200). #(0 1 2 3 4 5 6) do: [:i | output nextPutAll: (((self nameOfDay: i) asString) copyFrom: 1 to: 1)] andBetweenDo: [output space]. output cr. aDay := self year: year month: month newDay: 1. firstDayIndex := aDay dayNumber. lastDay := self year: year month: month + 1 newDay: 0. output cr. index := 0. [index < firstDayIndex] whileTrue: [output nextPutAll: ' '. index := index + 1]. counter := 1. [aDay <= lastDay] whileTrue: [aDay day < 10 ifTrue: [output space]. aDay day printOn: output. output space. aDay := aDay addDays: 1. counter := counter + 1. index := index + 1. (index \\ 7 = 0) ifTrue: [output cr]]. ^output contents! dayOfWeek: dayName "Dateクラスでは、曜日名を英語のシンボル名に決め打ちしているので、private methodを呼ぶように改良。" | dayNameArray result | dayNameArray := self initialize; dayNames. result := dayNameArray indexOf: (dayNameArray detect: [:each | each = dayName]). ^result - 1! ! !JapaneseDate class methodsFor: 'example' ! example1 "JapaneseDate example1" ^Array with: JapaneseDate today with: JapaneseDate dateAndTimeNow with: (JapaneseDate fromString: '1995/2/29') with: '96-12-31' asJapaneseDate! example10 "JapaneseDate example10" ^Array with: ('96/2/1' asJapaneseDate daysLeftInMonth) with: ('96/1/1' asJapaneseDate daysLeftInYear) with: ('96/2/29' asDate firstDayInMonth)! example11 "JapaneseDate example11" ^Array with: (JapaneseDate dayOfWeek: '日曜日') with: (JapaneseDate dayOfWeek: '月曜日') with: (JapaneseDate dayOfWeek: '火曜日') with: (JapaneseDate dayOfWeek: '土曜日')! example12 "JapaneseDate example12" ^Array with: ('1995/3/6' asDate previousWeekday: #Saturday) with: (JapaneseDate calendarForMonth: 2 year: 1995) with: (JapaneseDate calendarForMonth: 2 year: 1996) with: (JapaneseDate calendarForMonth: 9 year: 1951)! example2 "JapaneseDate example2" ^Array with: (JapaneseDate year: 1996 month: 2 + 1 newDay: 0) with: (JapaneseDate year: 1995 month: 3 newDay: 4 time: (Time hours: 12 minutes: 30 seconds: 55)) with: '1.1.1' asJapaneseDate with: (JapaneseDate year: 0 month: 1 newDay: 1)! example3 "JapaneseDate example3" ^Array with: (JapaneseDate jdToMjd: 0) with: (JapaneseDate jdToMjd: 2449780.5) with: '1.1.1' asJapaneseDate with: (JapaneseDate year: -1 month: 1 newDay: 1)! example4 "JapaneseDate example4" ^Array with: ('1995/3/1' asJapaneseDate dayIndex) with: (JapaneseDate daysInMonth: 2 forYear: 1996) with: (JapaneseDate daysInYear: 1996) with: ('96/12/31' asJapaneseDate dayOfYear)! example5 "JapaneseDate example5" ^Array with: (JapaneseDate indexOfMonth: #April) with: (JapaneseDate nameOfDay: 0) with: (JapaneseDate nameOfMonth: 11) with: (JapaneseDate mjdToJd: 0)! example6 "JapaneseDate example6" ^Array with: (JapaneseDate dateToYear: 1582 month: 10 day: 4) with: (JapaneseDate dateToYear: 1582 month: 10 day: 15)! example7 "JapaneseDate example7" ^Array with: ((JapaneseDate fromString: '95/3/4') year) with: ((JapaneseDate fromString: '95/3/4') month) with: ((JapaneseDate fromString: '95/3/4') dayAsFloat) with: ((JapaneseDate fromString: '95/3/4') day)! example8 "JapaneseDate example8" ^Array with: ('95/3/4' asJapaneseDate < '95/1/1' asJapaneseDate) with: ('95/3/4' asJapaneseDate = '95/3/4' asJapaneseDate) with: ('95/3/4' asJapaneseDate addDays: 365) with: ('1996.03.03' asJapaneseDate subtractDays: 365)! example9 "JapaneseDate example9" 0 to: 30 do: [:each | Transcript cr; show: ('1582/10/1' asJapaneseDate addDays: each) printString; tab; show: ('1582/10/1' asJapaneseDate addDays: each) mjd printString]. ^JapaneseDate calendarForMonth: 10 year: 1582! ! !JapaneseDate class methodsFor: 'initializing' ! holidayAt: year "Private -- year年の国民の休日をSortedCollectionとして求める" | holiday additionalHoliday | holiday := OrderedCollection new: 13. holiday add: (self year: year month: 1 newDay: 1). "元日" holiday add: (self year: year month: 1 newDay: 15). "成人の日" holiday add: (self year: year month: 2 newDay: 11). "建国記念日" holiday add: (self year: year month: 3 newDay: (self vernalEquinoxDay: year)). holiday add: (self year: year month: 4 newDay: 29). "緑の日" holiday add: (self year: year month: 5 newDay: 3). "憲法記念日" holiday add: (self year: year month: 5 newDay: 5). "子供の日" holiday add: (self year: year month: 9 newDay: 15). "敬老の日" holiday add: (self year: year month: 9 newDay: (self autumnalEquinoxDay: year)). holiday add: (self year: year month: 10 newDay: 10). "体育の日" holiday add: (self year: year month: 11 newDay: 3). "文化の日" holiday add: (self year: year month: 11 newDay: 23). "勤労感謝の日" holiday add: (self year: year month: 12 newDay: 23). "天皇誕生日" additionalHoliday := OrderedCollection new: 13. additionalHoliday add: (self year: year month: 5 newDay: 4). holiday do: [:eachHoliday | eachHoliday isSunday ifTrue: [additionalHoliday add: (eachHoliday addDays: 1)]]. "国民の休日が日曜日の場合の振り替え休日及び5月4日の収集" ^(holiday addAll: additionalHoliday; yourself) asSortedCollection! initialize self dayNames: #('日曜日' '月曜日' '火曜日' '水曜日' '木曜日' '金曜日' '土曜日'). self monthNames: #('1月' '2月' '3月' '4月' '5月' '6月' '7月' '8月' '9月' '10月' '11月' '12月'). ! ! !String methodsFor: 'as yet unclassified' ! asJapaneseDate "Answer a date parsed from the receiver." ^JapaneseDate fromString: self! ! !String methodsFor: 'as yet unclassified' ! asGregorianDate "Answer a date parsed from the receiver." ^GregorianDate fromString: self! ! !WinSystemTime methodsFor: 'as yet unclassified' ! asGregorianDate "Private - answer a Date object which contains the same date as the receiver." ^GregorianDate year: self wYear month: self wMonth newDay: self wDay ! ! !WinSystemTime methodsFor: 'as yet unclassified' ! asJapaneseDate "Private - answer a Date object which contains the same date as the receiver." ^JapaneseDate year: self wYear month: self wMonth newDay: self wDay ! !