📄 japanesecalendar.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 1 'Persistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "JapaneseCalendar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' CopyRight (c) 2005 Kelly Ethridge
'
' This file is part of VBCorLib.
'
' VBCorLib is free software; you can redistribute it and/or modify
' it under the terms of the GNU Library General Public License as published by
' the Free Software Foundation; either version 2.1 of the License, or
' (at your option) any later version.
'
' VBCorLib is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU Library General Public License for more details.
'
' You should have received a copy of the GNU Library General Public License
' along with Foobar; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'
' Module: JapaneseCalendar
'
''
' Provides functions for manipulate Japanese dates.
'
' @see Calendar
'
Option Explicit
Implements IObject
Implements Calendar
Private Const ERA_MEIJI As Currency = 58938451200000@
Private Const ERA_TAISHO As Currency = 60323443200000@
Private Const ERA_SHOWA As Currency = 60777993600000@
Private Const ERA_HEISEI As Currency = 62735817600000@
Private Const ERA_HEISEI_YR2 As Currency = 62766748800000@
Private Const ERA_SHOWA_YR2 As Currency = 60778598400000@
Private Const ERA_TAISHO_YR2 As Currency = 60336835200000@
Private Const ERA_MEIJI_YR2 As Currency = 58948387200000@
Private mEras() As Long
Private mTwoDigitYearMax As Long
Private mEraLengths() As Long
Private mEraStart() As Currency
Private mEraStartYR2() As Currency
Public Property Get Eras() As Long()
Eras = mEras
End Property
Public Property Get TwoDigitYearMax() As Long
TwoDigitYearMax = mTwoDigitYearMax
End Property
Public Property Let TwoDigitYearMax(ByVal RHS As Long)
If RHS < 100 Or RHS > 9999 Then _
Throw Cor.NewArgumentOutOfRangeException("Year must be between 100 and 9999 inclusively.", "TwoDigitYearMax", RHS)
mTwoDigitYearMax = RHS
End Property
Public Function AddDays(ByRef Time As Variant, ByVal Days As Long) As cDateTime
Set AddDays = cDateTime.GetcDateTime(Time).AddDays(Days)
End Function
Public Function AddHours(ByRef Time As Variant, ByVal Hours As Long) As cDateTime
Set AddHours = cDateTime.GetcDateTime(Time).AddHours(Hours)
End Function
Public Function AddMilliseconds(ByRef Time As Variant, ByVal Milliseconds As Double) As cDateTime
Set AddMilliseconds = cDateTime.GetcDateTime(Time).AddMilliseconds(Milliseconds)
End Function
Public Function AddMinutes(ByRef Time As Variant, ByVal Minutes As Long) As cDateTime
Set AddMinutes = cDateTime.GetcDateTime(Time).AddMinutes(Minutes)
End Function
Public Function AddMonths(ByRef Time As Variant, ByVal Months As Long) As cDateTime
Set AddMonths = cDateTime.GetcDateTime(Time).AddMonths(Months)
End Function
Public Function AddSeconds(ByRef Time As Variant, ByVal Seconds As Long) As cDateTime
Set AddSeconds = cDateTime.GetcDateTime(Time).AddSeconds(Seconds)
End Function
Public Function AddWeeks(ByRef Time As Variant, ByVal Weeks As Long) As cDateTime
Set AddWeeks = AddDays(Time, Weeks * 7)
End Function
Public Function AddYears(ByRef Time As Variant, ByVal Years As Long) As cDateTime
Set AddYears = cDateTime.GetcDateTime(Time).AddYears(Years)
End Function
Public Function GetDayOfMonth(ByRef Time As Variant) As Long
GetDayOfMonth = cDateTime.GetcDateTime(Time).Day
End Function
Public Function GetDayOfWeek(ByRef Time As Variant) As DayOfWeek
GetDayOfWeek = cDateTime.GetcDateTime(Time).DayOfWeek
End Function
Public Function GetDayOfYear(ByRef Time As Variant) As Long
GetDayOfYear = cDateTime.GetcDateTime(Time).DayOfYear
End Function
Public Function GetEra(ByRef Time As Variant) As Long
Dim dt As cDateTime
Dim i As Long
Dim ms As Currency
Set dt = cDateTime.GetcDateTime(Time)
Call VerifyDate(dt)
ms = dt.TotalMilliseconds
i = UBound(mEraStart)
Do While i >= 0
If ms >= mEraStart(i) Then Exit Do
i = i - 1
Loop
If i < 0 Then i = 0
GetEra = i + 1
End Function
Public Function GetHour(ByRef Time As Variant) As Long
GetHour = cDateTime.GetcDateTime(Time).Hour
End Function
Public Function GetMinute(ByRef Time As Variant) As Long
GetMinute = cDateTime.GetcDateTime(Time).Minute
End Function
Public Function GetMonth(ByRef Time As Variant) As Long
GetMonth = cDateTime.GetcDateTime(Time).Month
End Function
Public Function GetSecond(ByRef Time As Variant) As Long
GetSecond = cDateTime.GetcDateTime(Time).Second
End Function
Public Function GetMilliseconds(ByRef Time As Variant) As Double
GetMilliseconds = cDateTime.GetcDateTime(Time).Millisecond
End Function
Public Function GetDaysInMonth(ByVal Year As Long, ByVal Month As Long, Optional ByRef Era As Variant) As Long
Year = GetGregorianYear(Year, Era)
GetDaysInMonth = cDateTime.DaysInMonth(Year, Month)
End Function
Public Function GetYear(ByRef Time As Variant) As Long
Dim dt As cDateTime
Dim i As Long
Dim ms As Currency
Set dt = cDateTime.GetcDateTime(Time)
Call VerifyDate(dt)
ms = dt.TotalMilliseconds
i = UBound(mEraStart)
Do While i >= 0
If ms >= mEraStart(i) Then Exit Do
i = i - 1
Loop
If i < 0 Then i = 0
If ms < mEraStartYR2(i) Then
GetYear = 1
Else
GetYear = cDateTime.FromMilliseconds(ms - mEraStart(i)).Year + 1
End If
End Function
Public Function IsLeapYear(ByVal Year As Long, Optional ByRef Era As Variant) As Boolean
IsLeapYear = cDateTime.IsLeapYear(GetGregorianYear(Year, GetCurrentEra(Era)))
End Function
Public Function IsLeapMonth(ByVal Year As Long, ByVal Month As Long, Optional ByRef Era As Variant) As Boolean
If Month < 1 Or Month > 12 Then _
Throw Cor.NewArgumentOutOfRangeException("Month must be between 1 and 12.", "Month", Month)
If Month = 2 Then
IsLeapMonth = IsLeapYear(Year, Era)
End If
End Function
Public Function IsLeapDay(ByVal Year As Long, ByVal Month As Long, ByVal Day As Long, Optional ByRef Era As Variant) As Boolean
If Day < 1 Or Day > Me.GetDaysInMonth(Year, Month, Era) Then _
Throw Cor.NewArgumentOutOfRangeException("Day must be between 1 and " & GetDaysInMonth(Year, Month, Era) & " for the specified month.")
If Day = 29 Then IsLeapDay = IsLeapMonth(Year, Month, Era)
End Function
Public Function GetWeekOfYear(ByRef Time As Variant, ByVal Rule As CalendarWeekRule, ByVal FirstDayOfWeek As DayOfWeek) As Long
GetWeekOfYear = InternalGetWeekOfYear(Time, Rule, FirstDayOfWeek, Me)
End Function
Public Function GetMonthsInYear(ByVal Year As Long, Optional ByRef Era As Variant) As Long
Year = GetGregorianYear(Year, GetCurrentEra(Era))
GetMonthsInYear = 12
End Function
Public Function ToDateTime(ByVal Year As Long, ByVal Month As Long, ByVal Day As Long, ByVal Hour As Long, ByVal Minute As Long, ByVal Second As Long, ByVal Millisecond As Long, Optional ByRef Era As Variant) As cDateTime
Year = GetGregorianYear(Year, GetCurrentEra(Era))
Set ToDateTime = Cor.NewcDateTime(Year, Month, Day, Hour, Minute, Second, Millisecond)
End Function
Public Function ToFourDigitYear(ByVal Year As Long) As Long
If Year < 1 Or Year > 8011 Then _
Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_Range, 1, 8011), "Year", Year)
ToFourDigitYear = Year
End Function
Public Function GetDaysInYear(ByVal Year As Long, Optional ByRef Era As Variant) As Long
If IsLeapYear(Year, Era) Then
GetDaysInYear = 366
Else
GetDaysInYear = 365
End If
End Function
''
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -