Skip to content

Commit

Permalink
Enhance, adapt to LibreOffice 6.0
Browse files Browse the repository at this point in the history
Date_Parse would not work if year was between -9 and 0.
Milesian_Display now displays years with 3 digits, i.e. leading zeroes if necessary.
  • Loading branch information
Louis-Aime committed Aug 21, 2018
1 parent 97ca14d commit cb5a74c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
15 changes: 7 additions & 8 deletions CalendarFunctions/DateParse.xba
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
Attribute VB_Name = "DateParse"
'DateParse.
'Copyright Miletus SARL 2018. www.calendriermilesien.org
'For use as an MS Excel VBA module.
'Developped under Excel 2016
'Tested under MS Excel 2007 (Windows) and 2016 (Windows and MacOS)
'For use as an Open Office BASIC module.
'After a VBA module
'Tested under Libre Office 5.0 and 6.0 under MS Windows 10
'No warranty of conformance to business objectives
'Neither resale, neither transmission, neither compilation nor integration in other modules
'are permitted without authorisation
'DATE_PARSE, applied to any Date-Time expression as a string, returns the corresponding Excel Date series number.
'DATE_PARSE, applied to any Date-Time expression as a string, returns the corresponding Date series number.
'This module uses MilesianCalendar
'Do not apply to an Excel formatted date between 1 Jan and 29 Feb 1900. Hint: force input to Text format.
'Version of this module: M2018-08-28
'Version of this module: M2018-08-30

Const InvArgMsg = "Err :502" 'Error message displayed in place of function result, for non-typed functions (already defined in Milesian)

Function DATE_PARSE(TheCell As String) 'A String is converted into a Numeric that corresponds to a Date
Attribute DATE_PARSE.VB_Description = "Extract date and time value from string. Standard or Milesian expression. Earliest is 1/1/-9999. Negative years possible."
'TheCell holds a valid string for a date, either in milesian, either in a specific calendar,
'or in the standard calendar (In OpenOffice: Julio-gregorian, i.e. Julian until 4 Oct. 1582, then Gregorian).
'or in the default calendar. In OpenOffice, the Default calendar is Julian until 4 Oct. 1582, then Gregorian.
'TheCell is supposed a numeric date string. It shall not work with months expressed by their names.
'Summary:
' 1. Prepare, convert all in uppercase, trim
Expand All @@ -31,7 +30,7 @@ Attribute DATE_PARSE.VB_Description = "Extract date and time value from str
' 5. Find Month element after its pattern ("M" month marker)
' 6. Find Year element, of provide present year
' 7. Find Day element of provide "1" by default, return
' Note: authorised delimiters are "./-". Comma is dropped. m of Milesian month is recognised. Other lead to error.
' Note: authorised delimiters are "./-". Comma is dropped. "m" of Milesian month is recognised. Other lead to error.
' If as first character: canvas is yyy/mm/dd or similar, even M-yyy-mm-dd is possible.
' If not as first, find and extract "m", compute d, m and year elements, call MILESIAN_DATE.
On Error Goto ErrorHandler
Expand Down
7 changes: 4 additions & 3 deletions CalendarFunctions/MeanMoonPhase.xba
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
Attribute VB_Name = "MeanMoonPhase"
'MeanMoonPhase: Find a moon phase near a date.
'Copyright Miletus SARL 2017-2018. www.calendriermilesien.org
'For use as an MS Excel VBA module.
'Tested under MS Excel 2007 (Windows) and 2016 (Windows and MacOS).
'Extended after the same module in VBA
' -> MacOS epoch not taken into account (no way to reach the parameter)
'Tested under LibreOffice Calc V5.0 and 6.0
'No warranty.
'If transmitted, even with changes, present header shall be maintained in full.
'This package uses no other element.
Expand All @@ -18,7 +19,7 @@ Attribute VB_Name = "MeanMoonPhase"
'Parameters
' FromDate: a date and time UTC expressed in Excel
' MoonPhase: 0 or omitted: new moon; 1: first quarter; 2: full moon; 3: last quarter; <0 or >3: error.
'Version V2.0 M2018-02-10
'Version M2018-08-30

Const MeanSynodicMoon As Double = 29.53058883 'Mean duration of a synodic month in decimal days = 29d 12h 44mn 2s 7/8s
Const MeanNewMoon2000 As Double = 36531.59773 'G2000-01-06T14-20-44 TT, conventional date of a mean new moon
Expand Down
25 changes: 13 additions & 12 deletions CalendarFunctions/MilesianCalendar.xba
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
'For use as a Basic module.
'Extended after the same module in VBA
' -> MacOS epoch not taken into account (no way to reach the parameter)
'Tested under LibreOffice Calc V5.0.
'Tested under LibreOffice Calc V5.0 and 6.0
'No warranty.
'May be used for personal or professional purposes.
'If transmitted or integrated, even with changes, present header shall be maintained in full.
'Functions are aimed at extending Date & Time functions, and use similar parameters syntax in English
'Version V1.1 M2018-02-10
'Version M2018-08-30
'M2018-08-30: modified MILESIAN_DISPLAY, year always with at least 3-digits
'
Const MStoPresentEra As Long = 986163 'Offset between 1/1m/-800 epoch and Microsoft origin (1899-12-31T00 is 1)
Const MStoJulianMinus05 As Long = 2415018 'Offset between julian day epoch and Microsoft origin, minus 0.5
Expand Down Expand Up @@ -226,14 +227,20 @@ MILESIAN_TIME = InvArgMsg
End Function

Function MILESIAN_DISPLAY(TheDate, Optional Wtime) As String 'Default =False does not work
'Milesian date as a string, for a Date argument
'Milesian date as a string, for a Date argument. Year is always three digits.
On Error Goto ErrorHandler
Dim Y As Integer, M As Integer, Q As Integer, T As Variant
Dim Y As Integer, M As Integer, Q As Integer, T As Variant, YS As String
If IsMissing(Wtime) Then Wtime = 1
'Dim NumDate as Date
'NumDate = TheDate 'Force conversion or raise error
Milesian_DateElement TheDate, Y, M, Q, T 'Compute the figures of the milesian date
MILESIAN_DISPLAY = Q & " " & M & "m " & Y
'Fill year element with zeroes
YS = Y
If Y >= 0 And Y < 10 Then YS = "00" & Y
If Y >= 10 And Y < 100 Then YS = "0" & Y
If Y > -10 And Y < 0 Then YS = "-00" & (-Y)
If Y > -100 And Y <= -10 Then YS = "-0" & (-Y)
MILESIAN_DISPLAY = Q & " " & M & "m " & YS
If Wtime = 1 Then MILESIAN_DISPLAY = MILESIAN_DISPLAY & " " & T
Exit Function
ErrorHandler:
Expand Down Expand Up @@ -342,10 +349,4 @@ Function DAYOFWEEK_Ext(TheDate As Date, Optional DispType As Integer) As Integer

End Function

Sub Macro1

End Sub

Sub Macro2

End Sub</script:module>
</script:module>
2 changes: 1 addition & 1 deletion CalendarFunctions/script.xlb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="CalendarFunctions" library:readonly="false" library:passwordprotected="false">
<library:element library:name="MeanMoonPhase"/>
<library:element library:name="DateParse"/>
<library:element library:name="MeanMoonPhase"/>
<library:element library:name="MilesianCalendar"/>
</library:library>

0 comments on commit cb5a74c

Please sign in to comment.