VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CMailDate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'programmed by ShareVB
'gestion d'une date au format Mail MIME

Option Explicit
Option Compare Text

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(31) As Integer
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(31) As Integer
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type
Private Declare Function GetTimeZoneInformation Lib "kernel32.dll" (ByRef lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Private mvarDayOfWeek As String 'copie locale
Private mvarDay As String 'copie locale
Private mvarMonth As String 'copie locale
Private mvarYear As String 'copie locale
Private mvarHour As String 'copie locale
Private mvarMinute As String 'copie locale
Private mvarSecond As String 'copie locale
Private mvarZone As String 'copie locale
Private mvarVBDate As Date 'copie locale

'==================================================
'propriétés
'==================================================

Public Property Let VBDate(ByVal vData As Date)
Attribute VBDate.VB_HelpID = 150
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.VBDate = 5
    mvarVBDate = vData
    UpdateFromVBDate
End Property
Public Property Get VBDate() As Date
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.VBDate
    UpdateToVBDate
    VBDate = mvarVBDate
End Property

Public Property Let Zone(ByVal vData As String)
Attribute Zone.VB_HelpID = 148
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Zone = 5
    mvarZone = vData
End Property
Public Property Get Zone() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Zone
    Zone = mvarZone
End Property

Public Property Let MailSecond(ByVal vData As String)
Attribute MailSecond.VB_HelpID = 146
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Second = 5
    mvarSecond = vData
End Property
Public Property Get MailSecond() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Second
    MailSecond = mvarSecond
End Property

Public Property Let MailMinute(ByVal vData As String)
Attribute MailMinute.VB_HelpID = 144
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Minute = 5
    mvarMinute = vData
End Property
Public Property Get MailMinute() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Minute
    MailMinute = mvarMinute
End Property

Public Property Let MailHour(ByVal vData As String)
Attribute MailHour.VB_HelpID = 142
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Hour = 5
    mvarHour = vData
End Property
Public Property Get MailHour() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Hour
    MailHour = mvarHour
End Property

Public Property Let MailYear(ByVal vData As String)
Attribute MailYear.VB_HelpID = 140
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Year = 5
    mvarYear = vData
End Property
Public Property Get MailYear() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Year
    MailYear = mvarYear
End Property

Public Property Let MailMonth(ByVal vData As String)
Attribute MailMonth.VB_HelpID = 138
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Month = 5
    mvarMonth = vData
End Property
Public Property Get MailMonth() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Month
    MailMonth = mvarMonth
End Property

Public Property Let MailDay(ByVal vData As String)
Attribute MailDay.VB_HelpID = 136
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Day = 5
    mvarDay = vData
End Property
Public Property Get MailDay() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Day
    MailDay = mvarDay
End Property

Public Property Let MailDayOfWeek(ByVal vData As String)
Attribute MailDayOfWeek.VB_HelpID = 134
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.DayOfWeek = 5
    mvarDayOfWeek = vData
End Property
Public Property Get MailDayOfWeek() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.DayOfWeek
    MailDayOfWeek = mvarDayOfWeek
End Property

'==================================================
'méthodes privées
'==================================================

Private Function GetMonthValue(szMonth As String) As Long
    Select Case szMonth
        Case "Jan"
            GetMonthValue = 1
        Case "Feb"
            GetMonthValue = 2
        Case "Mar"
            GetMonthValue = 3
        Case "Apr"
            GetMonthValue = 4
        Case "May"
            GetMonthValue = 5
        Case "Jun"
            GetMonthValue = 6
        Case "Jul"
            GetMonthValue = 7
        Case "Aug"
            GetMonthValue = 8
        Case "Sep"
            GetMonthValue = 9
        Case "Oct"
            GetMonthValue = 10
        Case "Nov"
            GetMonthValue = 11
        Case "Dec"
            GetMonthValue = 12
    End Select
End Function

Private Function GetMonthName(ByVal lMonth As Long) As String
    Select Case lMonth
        Case 1
            GetMonthName = "Jan"
        Case 2
            GetMonthName = "Feb"
        Case 3
            GetMonthName = "Mar"
        Case 4
            GetMonthName = "Apr"
        Case 5
            GetMonthName = "May"
        Case 6
            GetMonthName = "Jun"
        Case 7
            GetMonthName = "Jul"
        Case 8
            GetMonthName = "Aug"
        Case 9
            GetMonthName = "Sep"
        Case 10
            GetMonthName = "Oct"
        Case 11
            GetMonthName = "Nov"
        Case 12
            GetMonthName = "Dec"
    End Select
End Function

Private Function GetDayOfWeekName(ByVal lDayOfWeek As Long) As String
    Select Case lDayOfWeek
        Case vbMonday
            GetDayOfWeekName = "Mon"
        Case vbTuesday
            GetDayOfWeekName = "Tue"
        Case vbWednesday
            GetDayOfWeekName = "Wed"
        Case vbThursday
            GetDayOfWeekName = "Thu"
        Case vbFriday
            GetDayOfWeekName = "Fri"
        Case vbSaturday
            GetDayOfWeekName = "Sat"
        Case vbSunday
            GetDayOfWeekName = "Sun"
    End Select
End Function

Private Function GetTimeZone() As String
Dim tz As TIME_ZONE_INFORMATION
Dim hh As Long, mm As Long, s As String

GetTimeZoneInformation tz

If tz.Bias > 0 Then s = "-" Else s = "+"
tz.Bias = Abs(tz.Bias)

hh = tz.Bias \ 60
mm = tz.Bias Mod 60
GetTimeZone = s & Right$("00" & hh, 2) & Right$("00" & mm, 2)
End Function

Private Sub UpdateToVBDate()
mvarVBDate = DateSerial(Val(mvarYear), GetMonthValue(mvarMonth), Val(mvarDay)) + TimeSerial(Val(mvarHour), Val(mvarMinute), Val(mvarSecond))
End Sub

Private Sub UpdateFromVBDate()
mvarHour = Right$("00" & Hour(mvarVBDate), 2)
mvarMinute = Right$("00" & Minute(mvarVBDate), 2)
mvarSecond = Right$("00" & Second(mvarVBDate), 2)

mvarDay = Right$("00" & Day(mvarVBDate), 2)
mvarMonth = GetMonthName(Month(mvarVBDate))
mvarYear = Right$("0000" & Year(mvarVBDate), 4)

mvarDayOfWeek = GetDayOfWeekName(Weekday(mvarVBDate))

mvarZone = GetTimeZone
End Sub

'==================================================
'méthodes publiques
'==================================================

Public Sub Parse(ByVal szDate As String)
Dim posvirg As Long
Dim lszDatePart() As String, lszTime() As String

On Error GoTo fin

szDate = Trim$(szDate)

posvirg = InStr(szDate, ",")
If posvirg > 0 Then
    mvarDayOfWeek = Mid$(szDate, 1, posvirg - 1)
    szDate = Trim$(Mid$(szDate, posvirg + 1))
End If

lszDatePart = Split(szDate, " ")

mvarDay = Trim$(lszDatePart(0))
mvarMonth = Trim$(lszDatePart(1))
mvarYear = Trim$(lszDatePart(2))

lszTime = Split(Trim$(lszDatePart(3)) & ":", ":")
mvarHour = Trim$(lszTime(0))
mvarMinute = Trim$(lszTime(1))
mvarSecond = Trim$(lszTime(2))

mvarZone = Trim$(lszDatePart(4))

fin:
End Sub

Public Function Make(Optional bDayOfWeek As Boolean = False) As String
    If bDayOfWeek Then
        Make = mvarDayOfWeek & ", " & mvarDay & " " & mvarMonth & " " & mvarYear & " " & mvarHour & ":" & mvarMinute & ":" & mvarSecond & " " & mvarZone
    Else
        Make = mvarDay & " " & mvarMonth & " " & mvarYear & " " & mvarHour & ":" & mvarMinute & ":" & mvarSecond & " " & mvarZone
    End If
End Function
