Bug 136112 - Basic Time function returns inconsistent datatype
Summary: Basic Time function returns inconsistent datatype
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
Whiteboard: target:7.1.0
Depends on:
Blocks: Macro-VBA Macro-StarBasic
  Show dependency treegraph
Reported: 2020-08-25 14:25 UTC by Alain Romedenne
Modified: 2020-09-09 16:16 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description Alain Romedenne 2020-08-25 14:25:37 UTC
Time and Time$ both return a String, while the former should return a Variant (Date) which would be consistent with VBA.

Time should be documented as a function - not as a statement - as changing time on Unix platforms requires admin privilege. Time statement does not function under Windows and should therefore be marked as unsupported. 

Steps to Reproduce:
1. Example Basic code:
Private Sub _Time_
	Print TypeName(Time()), VarType(Time), TypeName(Time$), VarType(Time$())
	Time = "18:20:15" ' does nothing
End Sub
2. Run and observe the routine results

Actual Results:
Time$ returns a locale-dependant String output
Time  returns a locale-dependant String output

Expected Results:
Time$ to return a locale-dependant String output
Time to return a Variant of Type 7 (Date/Time)

Reproducible: Always

User Profile Reset: No

Additional Info:
Version: (x64)
Build ID: 3d775be2011f3886db32dfd395a6a6d1ca2630ff
CPU threads: 12; OS: Windows 10.0 Build 17134; UI render: default; VCL: win; 
Locale: en-GB (en_IE); UI-Language: en-GB
Calc: threaded
Comment 1 Andreas Heinisch 2020-09-02 10:20:29 UTC
Confirmed in:

Version: (x64)
Build-ID: a187af327633f5f00363be5131bd21a13e0f1a7b
CPU-Threads: 4; BS: Windows 10.0; UI-Render: GL; VCL: win; 
Gebietsschema: de-DE (de_DE); UI-Sprache: de-DE
Calc: CL

However, Time$ does not return a locale-dependent String:
Comment 3 Alain Romedenne 2020-09-03 08:53:54 UTC
As opposed to Time function, Date[$] function behaves consistently:

- Date returns a Variant
- Date$ returns a String

Similarly to Time function, Date should be documented as function instead of a statement. As platform date updates are restricted to worksattion admins.
Comment 4 Alain Romedenne 2020-09-03 08:58:00 UTC

Sub _Date_
	Print Date, TypeName(Date()), VarType(Date), Date$, TypeName(Date$), VarType(Date$())
	Date = "February 12, 1985" ' does nothing
End Sub

- VBA Date function
- VBA Date statement
Comment 5 Commit Notification 2020-09-03 16:20:43 UTC
Alain Romedenne committed a patch related to this issue.
It has been pushed to "master":


tdf#136112 Date/Time are LibO Basic functions not statements
Comment 6 Commit Notification 2020-09-08 15:19:02 UTC
Alain Romedenne committed a patch related to this issue.
It has been pushed to "master":


tdf#136112 Unit test for Date() Basic function

It will be available in 7.1.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:

Affected users are encouraged to test the fix and report feedback.
Comment 7 Alain Romedenne 2020-09-09 16:16:48 UTC
Suggestion for a QA unit test routine:

Function doUnitTest as Integer
  ''' Return 'text' OR 'date' variable '''

  If ( TypeName(Time$)<>"String" Or Vartype(Time())<>V_DATE ) Then
    doUnitTest = 0 ' not successful
    doUnitTest = 1 ' Ok
  End If
End Function

Sub DEV_TST : MsgBox doUnitTesT : End Sub