Skip to content

[Bug]: time functions mishandle large hours and fractional seconds #24784

Description

@LeftHandCold

Is there an existing issue for the same bug?

I have checked the existing issues. #24481 is about unsupported functions on 3.0-dev; this issue is about incorrect results for already-supported time functions on 4.0-dev.

Branch Name

4.0-dev

Commit ID

47459ce

Other Environment Information

  • Hardware parameters: N/A
  • OS type: N/A
  • Others: verified by source inspection on 4.0-dev

Actual Behavior

Several MySQL-compatible time functions return incorrect results for TIME values whose hour part is greater than 23, or for MAKETIME seconds with fractional precision:

  1. HOUR(TIME) folds the hour with % 24, so a TIME interval such as 272:59:59 returns 8 instead of the full hour value.
  2. TIME_FORMAT(time, "%T") folds the hour with % 24, so 123:45:06 formats as 03:45:06 instead of preserving the full hour part.
  3. MAKETIME(hour, minute, second) truncates fractional seconds for floating second arguments and always constructs the result with microseconds set to 0.

Expected Behavior

MatrixOne should match MySQL TIME semantics:

  • HOUR("272:59:59") should return 272.
  • TIME_FORMAT("123:45:06", "%T") should return 123:45:06.
  • MAKETIME(12, 34, 56.789012) should preserve the fractional seconds and return 12:34:56.789012.

Steps to Reproduce

SELECT HOUR(CAST("272:59:59" AS TIME));
SELECT TIME_FORMAT(CAST("123:45:06" AS TIME), "%T");
SELECT MAKETIME(12, 34, 56.789012);

Additional information

The source currently contains these incorrect paths on 4.0-dev:

  • pkg/sql/plan/function/func_unary.go: TimeToHour returns hour % 24.
  • pkg/sql/plan/function/func_binary.go: TIME_FORMAT %T uses hour%24.
  • pkg/sql/plan/function/func_binary.go: MakeTime truncates floating seconds and passes 0 microseconds to types.TimeFromClock.

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't workingseverity/s0Extreme impact: Cause the application to break down and seriously affect the use

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions