Option Explicit
Sub FinalRegexTest()
Dim oMatches As Object
Dim iMatch As Integer
Dim oMatch As Object
Dim strTemp As String
Dim RegExp As Object
Set RegExp = CreateObject("VBScript.RegExp")
If ActiveDocument.Tables.Count > 0 Then
MsgBox "àðå îöèòøéí ìà ðéúï ìäôòéì úëåðä æå áîñîê ùéù áå èáìàåú."
Exit Sub
End If
With RegExp
.Global = True
.Pattern = "\d{1,2}[\./-]\d{1,2}[\./-]\d{2,4}"
.MultiLine = False
Set oMatches = .Execute(ActiveDocument.Range.Text)
For iMatch = oMatches.Count To 1 Step -1
Set oMatch = oMatches(iMatch - 1)
strTemp = Replace(oMatch, ".", "-")
If IsDate(strTemp) Then
ActiveDocument.Range(oMatch.FirstIndex, oMatch.FirstIndex + oMatch.Length) = GregToHeb(CDate(strTemp)) & " (" & oMatch & ")"
End If
strTemp = ""
Next
End With
Set oMatches = Nothing
Set oMatch = Nothing
Set RegExp = Nothing
End Sub
Public Function GregToHeb(GrDate As Date, Optional DateString As String = "DDD MM YYYY") As Variant
'äôåð÷öéä îçæéøä úàøéê òáøé ëáéèåé è÷ñèåàìé òáåø úàøéê âøâåøéàðé ðúåï
'äôåð÷öéä î÷áìú ëôøîèøéí úàøéê òáøé åáéèåé è÷ñèåàìé
'åîçæéøä áéèåé ùáå îöééðé äî÷åí îåçìôéí ò"é øëéáé äúàøéê äòáøé ëãì÷îï
'D - éåí áçåãù áñôøåú
'DD - éåí áçåãù áàåúéåú ììà âøùééí
'DDD - éåí áçåãù áàåúéåú ëåìì âøùééí
'M - çåãù áñôøåú: úùøé = 1, àãø = 6, àãø à = 6.1, àãø á = 6.2
'MM - ùí äçåãù áîéìéí
'Y - ùðä áñôøåú ììà àìôéí
'YY - ùðä áñôøåú ëåìì àìôéí
'YYY - ùðä áàåúéåú, ììà àìôéí, ììà âøùééí
'YYYY - ùðä áàåúéåú ëåìì âøùééí
'äôåð÷öéä àéðä øâéùä ìàåúéåú âãåìåú àå ÷èðåú
'îçøåæú áøéøú äîçãì äéà: "DDD MM YYY"
Dim dtPreviousRoshHashanah As Date, dtNextRoshHashanah As Date
Dim intYearLen As Integer, intDaysInYear As Integer
Dim intDayNum As Integer, intCurrentMonthLength As Integer, intPreviousMonthLength As Integer
Dim arrMonthLength, arrMonthNames, arrMonthNumbers, arrWeekdayNames
Dim strTemp As String
Dim lngMonth, lngDay, lngYear As Long
arrWeekdayNames = Array("ùáú", "øàùåï", "ùðé", "ùìéùé", "øáéòé", "çîéùé", "ùùé", "ùáú")
intDayNum = Weekday(GrDate)
strTemp = UCase(DateString)
lngYear = Year(GrDate) + 3761
dtPreviousRoshHashanah = fRoshHashanah(lngYear)
If dtPreviousRoshHashanah <= GrDate Then
dtNextRoshHashanah = fRoshHashanah(lngYear + 1)
Else
dtNextRoshHashanah = dtPreviousRoshHashanah
lngYear = lngYear - 1
dtPreviousRoshHashanah = fRoshHashanah(lngYear)
End If
intYearLen = dtNextRoshHashanah - dtPreviousRoshHashanah
intDaysInYear = GrDate - dtPreviousRoshHashanah
Select Case intYearLen
Case 353
arrMonthLength = Array(0, 30, 59, 88, 117, 147, 176, 206, 235, 265, 294, 324, 353)
Case 354
arrMonthLength = Array(0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325, 354)
Case 355
arrMonthLength = Array(0, 30, 60, 90, 119, 149, 178, 208, 237, 267, 296, 326, 355)
Case 383
arrMonthLength = Array(0, 30, 59, 88, 117, 147, 177, 206, 236, 265, 295, 324, 354, 383)
Case 384
arrMonthLength = Array(0, 30, 59, 89, 118, 148, 178, 207, 237, 266, 296, 325, 355, 384)
Case 385
arrMonthLength = Array(0, 30, 60, 90, 119, 149, 179, 208, 238, 267, 297, 326, 356, 385)
End Select
If intYearLen < 380 Then
arrMonthNames = Array("", "úùøé", "çùåï", "ëñìå", "èáú", "ùáè", "àãø", "ðéñï", "àééø", "ñéåï", "úîåæ", "àá", "àìåì")
arrMonthNumbers = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
Else
arrMonthNames = Array("", "úùøé", "çùåï", "ëñìå", "èáú", "ùáè", "àãø à", "àãø á", "ðéñï", "àééø", "ñéåï", "úîåæ", "àá", "àìåì")
arrMonthNumbers = Array(0, 1, 2, 3, 4, 5, 6.1, 6.2, 7, 8, 9, 10, 11, 12)
End If
lngMonth = 1
While intDaysInYear >= arrMonthLength(lngMonth)
lngMonth = lngMonth + 1
Wend
lngDay = intDaysInYear - arrMonthLength(lngMonth - 1) + 1
intCurrentMonthLength = arrMonthLength(lngMonth) - arrMonthLength(lngMonth - 1)
If lngMonth = 1 Then
intPreviousMonthLength = 29
Else
intPreviousMonthLength = arrMonthLength(lngMonth - 1) - arrMonthLength(lngMonth - 2)
End If
strTemp = Replace(strTemp, "YYYY", fGimatria(lngYear, False, True, True))
strTemp = Replace(strTemp, "YYY", fGimatria(lngYear, False, False))
strTemp = Replace(strTemp, "YY", lngYear)
strTemp = Replace(strTemp, "Y", lngYear Mod 1000)
strTemp = Replace(strTemp, "MM", arrMonthNames(lngMonth))
strTemp = Replace(strTemp, "M", arrMonthNumbers(lngMonth))
strTemp = Replace(strTemp, "DDD", fGimatria(lngDay, False, True, True))
strTemp = Replace(strTemp, "DD", fGimatria(lngDay, False, False, True))
strTemp = Replace(strTemp, "D", lngDay)
GregToHeb = strTemp
End Function
Public Function HebToGreg(lngHebYear As Long, dblHebMonth As Double, lngHebDay As Long) As Date
'äôåð÷öéä î÷áìú úàøéê òáøé îìà, åîçæéøä àú äúàøéê äìåòæé ùáå äåà çì
'äôåð÷öéä î÷áìú ùðä, çåãù, åéåí áìåç äòáøé, åîçæéøä úàøéê ìåòæé
'àí äçåãù äåà àãø à àå àãø á, áùðä ùàéðä îòåáøú - éåçæø úàøéê áàãø
'àí äçåãù äåà àãø ñúí áùðä îòåáøú - éåçæø úàøéê áàãø á
'àí äúàøéê äåà ì çùåï àå ì ëñìå áùðä ùáä àéï úàøéê ëæä - äúàøéê ééãçä áéåí
Dim strTemp
Dim ThisYearRoshHashanah, NextYearRoshHashanah
Dim intYearLen As Integer
Dim arrMonthLength
Dim dblHebMonth As Double
ThisYearRoshHashanah = fRoshHashanah(lngHebYear)
NextYearRoshHashanah = fRoshHashanah(lngHebYear + 1)
intYearLen = NextYearRoshHashanah - ThisYearRoshHashanah
Select Case intYearLen
Case 353
arrMonthLength = Array(0, 30, 59, 88, 117, 147, 176, 206, 235, 265, 294, 324, 353)
Case 354
arrMonthLength = Array(0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325, 354)
Case 355
arrMonthLength = Array(0, 30, 60, 90, 119, 149, 178, 208, 237, 267, 296, 326, 355)
Case 383
arrMonthLength = Array(0, 30, 59, 88, 117, 147, 177, 206, 236, 265, 295, 324, 354, 383)
Case 384
arrMonthLength = Array(0, 30, 59, 89, 118, 148, 178, 207, 237, 266, 296, 325, 355, 384)
Case 385
arrMonthLength = Array(0, 30, 60, 90, 119, 149, 179, 208, 238, 267, 297, 326, 356, 385)
End Select
If intYearLen < 380 Then
dblHebMonth = Int(dblHebMonth)
Else
If dblHebMonth < 6.2 Then
dblHebMonth = Int(dblHebMonth)
Else
dblHebMonth = Int(dblHebMonth) + 1
End If
End If
strTemp = ThisYearRoshHashanah + arrMonthLength(dblHebMonth - 1) + lngHebDay - 1
HebToGreg = strTemp
End Function
Private Function fRoshHashanahMolad(lngHebYear As Long) As Variant
'äôåð÷öéä îçùáú àú úàøéê åùòú äîåìã ùì øàù äùðä òáåø ùðä òáøéú ðúåðä
'äôåð÷öéä î÷áìú ëôøîèø îñôø ùì ùðä òáøéú (ëåìì àìôéí) åîçæéøä úàøéê+ùòä
Dim dblMonthLength As Double
Dim arrAccumaltiveMonthsPerYear
Dim lngDistanceFromMoladTohu As Long
Dim dblMoladTohu As Double
'îåìã úåäå - äùòåú ìôé 0 = 18:00
dblMoladTohu = -2067021.0337963
'àåøê çåãù - ë"è é"á úùö"â
dblMonthLength = 29 + (12 + 793 / 1080) / 24
'îòøê öáéøú çåãùéí îúçéìú äîçæåø òã úçéìú äùðä
arrAccumaltiveMonthsPerYear = Array(-13, 0, 12, 24, 37, 49, 61, 74, 86, 99, 111, 123, 136, 148, 160, 173, 185, 197, 210)
'ñä"ë çåãùéí îîåìã úåäå
lngDistanceFromMoladTohu = Int(lngHebYear / 19) * 235 + arrAccumaltiveMonthsPerYear(lngHebYear Mod 19)
'úàøéê åùòú îåìã øàù äùðä
fRoshHashanahMolad = lngDistanceFromMoladTohu * dblMonthLength + dblMoladTohu
End Function
Private Function fRoshHashanah(lngHebYear As Long) As Date
'äôåð÷öéä îçùáú àú äúàøéê äâøâåøéàðé ùì øàù äùðä òáåø ùðä òáøéú ðúåðä
'äôåð÷öéä î÷áìú ëôøîèø îñôø ùðä òáøéú (ëåìì àìôéí) åîçæéøä úàøéê âøâåøéàðé
Dim strTemp As Date
Dim intDayNumber As Integer
Dim arrLengthOfYears As Variant
Dim dblMoladTimeDecimal As Double
'îòøê ùðéí øâéìåú åîòåáøåú - âå"ç àãæ"è
arrLengthOfYears = Array(13, 12, 12, 13, 12, 12, 13, 12, 13, 12, 12, 13, 12, 12, 13, 12, 12, 13, 12)
'æîï îåìã øàù äùðä + 6 ùòåú ëãé ìòáåø ìéîîä ùáä 0 = çöåú
strTemp = fRoshHashanahMolad(lngHebYear) + 0.25
'dblMoladTimeDecimal - çì÷ äéîîä: ùòú äîåìã áùáø òùøåðé ùì éîéí
dblMoladTimeDecimal = strTemp - Int(strTemp)
'àøáò äãçéåú
'îåìã æ÷ï
If dblMoladTimeDecimal >= 18 / 24 Then
strTemp = strTemp + 1
End If
'ìà àã"å øàù
intDayNumber = Weekday(strTemp)
If intDayNumber = 1 Or intDayNumber = 4 Or intDayNumber = 6 Then
strTemp = strTemp + 1
End If
'â"è ø"ã áùðä ôùåèä
If arrLengthOfYears(lngHebYear Mod 19) = 12 And Weekday(strTemp) = 3 And dblMoladTimeDecimal >= (9 + 204 / 1080) / 24 And dblMoladTimeDecimal < 18 / 24 Then
strTemp = strTemp + 2
End If
'áè"å ú÷ô"è àçøé òéáåø
If arrLengthOfYears((lngHebYear - 1) Mod 19) = 13 And Weekday(strTemp) = 2 And dblMoladTimeDecimal >= (15 + 589 / 1080) / 24 And dblMoladTimeDecimal < 18 / 24 Then
strTemp = strTemp + 1
End If
'úàøéê øàù äùðä
fRoshHashanah = Int(strTemp)
End Function
'.äçæø àú äîñôø áàåôï âéîèøé áàåúéåú
'äôåð÷öéä ø÷åøñéáéú ëãé ìëìåì òøëéí äâãåìéí
'àå ùååéí ìàìó
'éù áå 4 àøâåîðèéí:
' 1. äîñôø äîáå÷ù
' 2. äàí ìëìåì àìôéí (ëâåï ä'úùò"â) (ëï/ìà) áøéøú äîçãì äéà ìà
' 3. äàí ìëìåì âøùééí (ëâåï úùò"â) (ëï/ìà) áøéøú äîçãì äéà ëï
' 4. äàí ìäùúîù áîñôøéí "ð÷ééí" (ëâåï òøä áî÷åí øòä) (ëï/ìà) áøéøú äîçãì äéà ëï
Private Function fGimatria(ByVal intNum As Integer, _
Optional blnIncludeThousands As Boolean = False, _
Optional blnIncludeQuotes As Boolean = True, _
Optional blnGoodNumbers As Boolean = True) As String
'intNum - îñôø ùìí ìäîøä
Dim strTemp As String
Dim Digit As Integer
strTemp = ""
'àí äîñôø âãåì (àå ùååä) ìàìó, îöà àú äâéîèøéä ùì
'äçìå÷ä äùìîä ùì äîñôø áàìó
If intNum >= 1000 Then
strTemp = fGimatria(intNum \ 1000)
intNum = intNum Mod 1000
strTemp = strTemp & Chr$(39) ' äåñôú âøù àçø àåú äàìôéí
End If
'ñôøú äîàåú
'àí äîñôø âãåì àå ùååä ì-900
'äåñó ÷ãåîú ùì äàåúéåú úú÷
If intNum >= 900 Then strTemp = strTemp + "úú÷"
'àí äîñôø âãåì àå ùååä ì-500, äåñó ÷ãåîú ùì
'äàåú ú' åàåú ðåñôú áéï ÷-ú
If intNum >= 500 And intNum < 900 Then
strTemp = strTemp + "ú"
strTemp = strTemp + Chr$(Asc("÷") + (intNum \ 100 - 5))
End If
'àí äîñôø âãåì î-100 äåñó àåú áéï ÷-ú
If intNum >= 100 And intNum < 500 Then
strTemp = strTemp + Chr$(Asc("÷") + (intNum \ 100 - 1))
End If
'ñôøú äòùøåú
'àí äîñôø ììà îàåú âãåì î-10 äåñó àú äàåú äîúàéîä
Digit = (intNum Mod 100) \ 10
If Digit Then
Select Case Digit 'äñôøä
Case 1: strTemp = strTemp + "é"
Case 2: strTemp = strTemp + "ë"
Case 3: strTemp = strTemp + "ì"
Case 4: strTemp = strTemp + "î"
Case 5 To 7: strTemp = strTemp + Chr$(Asc("ð") + Digit - 5)
Case 8: strTemp = strTemp + "ô"
Case 9: strTemp = strTemp + "ö"
End Select
End If
'àí éù ñôøú àçãåú äåñó àåúä
Digit = (intNum Mod 10)
If Digit Then strTemp = strTemp + Chr$(Asc("à") + Digit - 1)
'îðò éä åéå
'
' àéï èòí ìäùúîù òí "Replace" àí àéï ååãàåú ùéîöà äè÷ñè ìäçìôä
' îëéåï ùôåð÷öéä æå úîéã îòúé÷ä àú äîçøåæú âí àí àéï îä ìäçìéó
' åäòú÷ä æå àéèéú
' ìëï ÷åãí ðùúîù òí "InStr" åø÷ àí ðîöà äè÷ñè ìäçìôä ð÷øà ì"Replace"
If InStr(strTemp, "éä") <> 0 Then strTemp = Replace(strTemp, "éä", "èå")
If InStr(strTemp, "éå") <> 0 Then strTemp = Replace(strTemp, "éå", "èæ")
If blnGoodNumbers Then
' îùðä ùðéí "øòåú" ìð÷éåú
strTemp = Replace(strTemp, "øöç", "øçö")
strTemp = Replace(strTemp, "øò", "òø")
strTemp = Replace(strTemp, "øòä", "òøä")
strTemp = Replace(strTemp, "ùã", "ãù")
strTemp = Replace(strTemp, "ùîã", "ãùî")
End If
If blnIncludeQuotes Then
' äåñôú âøùééí ìôðé äàåú äàçøåðä àí éù éåúø îùðé úååéí áîçøåæú
If Len(strTemp) >= 2 Then
strTemp = Mid$(strTemp, 1, Len(strTemp) - 1) & Chr$(34) & Mid$(strTemp, Len(strTemp), 1)
End If
End If
If Not blnIncludeThousands Then
' îåøéã àú äàåú äîñîì àú äàìôéí
If InStr(strTemp, "'") Then
If Len(strTemp) > 2 Then
' Debug.Print "before: " & strTemp
strTemp = Right$(strTemp, Len(strTemp) - 2)
' Debug.Print "after: " & strTemp
End If
End If
End If
' îçæéø àú äúåöàä äñåôéú
fGimatria = strTemp
End Function