Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
5d6346a1
Commit
5d6346a1
authored
6 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
More flow
parent
d9edcb84
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/lib/formatting.js
+10
-4
10 additions, 4 deletions
frontend/src/metabase/lib/formatting.js
frontend/src/metabase/lib/formatting/date.js
+46
-10
46 additions, 10 deletions
frontend/src/metabase/lib/formatting/date.js
with
56 additions
and
14 deletions
frontend/src/metabase/lib/formatting.js
+
10
−
4
View file @
5d6346a1
...
...
@@ -37,6 +37,12 @@ import type { Column, Value } from "metabase/meta/types/Dataset";
import
type
{
DatetimeUnit
}
from
"
metabase/meta/types/Query
"
;
import
type
{
Moment
}
from
"
metabase/meta/types
"
;
import
type
{
DateStyle
,
TimeStyle
,
TimeEnabled
,
}
from
"
metabase/lib/formatting/date
"
;
export
type
FormattingOptions
=
{
// GENERIC
column
?:
Column
|
Field
,
...
...
@@ -68,12 +74,12 @@ export type FormattingOptions = {
link_text
?:
string
,
// DATE/TIME
// date/timeout style string that is used to derive a date_format or time_format for different units, see metabase/lib/formatting/date
date_style
?:
string
,
time_style
?:
string
,
date_format
?:
string
,
date_style
?:
DateStyle
,
date_abbreviate
?:
boolean
,
date_format
?:
string
,
time_style
?:
TimeStyle
,
time_enabled
?:
TimeEnabled
,
time_format
?:
string
,
time_enabled
?:
null
|
"
minutes
"
|
"
seconds
"
|
"
milliseconds
"
,
};
type
FormattedString
=
string
|
React$Element
<
any
>
;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/lib/formatting/date.js
+
46
−
10
View file @
5d6346a1
const
DEFAULT_DATE_FORMATS
=
{
/* @flow */
import
type
{
DatetimeUnit
}
from
"
metabase/meta/types/Query
"
;
export
type
DateStyle
=
|
"
M/D/YY
"
|
"
D/M/YY
"
|
"
YYYY/M/D
"
|
"
MMMM D, YYYY
"
|
"
MMMM D, YYYY
"
|
"
D MMMM, YYYY
"
|
"
dddd, MMMM D, YYYY
"
;
export
type
TimeStyle
=
"
h:mm A
"
|
"
k:mm
"
;
export
type
MomentFormat
=
string
;
// moment.js format strings
export
type
DateFormat
=
MomentFormat
;
export
type
TimeFormat
=
MomentFormat
;
export
type
TimeEnabled
=
null
|
"
minutes
"
|
"
seconds
"
|
"
milliseconds
"
;
const
DEFAULT_DATE_FORMATS
:
{
[
unit
:
DatetimeUnit
]:
MomentFormat
}
=
{
year
:
"
YYYY
"
,
quarter
:
"
[Q]Q - YYYY
"
,
"
minute-of-hour
"
:
"
m
"
,
...
...
@@ -12,7 +33,9 @@ const DEFAULT_DATE_FORMATS = {
};
// a "date style" is essentially a "day" format with overrides for larger units
const
DATE_STYLE_TO_FORMAT
=
{
const
DATE_STYLE_TO_FORMAT
:
{
[
style
:
DateStyle
]:
{
[
unit
:
DatetimeUnit
]:
MomentFormat
},
}
=
{
"
M/D/YY
"
:
{
month
:
"
M/YY
"
,
},
...
...
@@ -35,9 +58,12 @@ const DATE_STYLE_TO_FORMAT = {
},
};
export
const
DEFAULT_DATE_STYLE
=
"
MMMM D, YYYY
"
;
export
const
DEFAULT_DATE_STYLE
:
DateStyle
=
"
MMMM D, YYYY
"
;
export
function
getDateFormatFromStyle
(
style
,
unit
)
{
export
function
getDateFormatFromStyle
(
style
:
DateStyle
,
unit
:
DatetimeUnit
,
):
DateFormat
{
if
(
DATE_STYLE_TO_FORMAT
[
style
])
{
if
(
DATE_STYLE_TO_FORMAT
[
style
][
unit
])
{
return
DATE_STYLE_TO_FORMAT
[
style
][
unit
];
...
...
@@ -51,18 +77,28 @@ export function getDateFormatFromStyle(style, unit) {
return
style
;
}
const
UNITS_WITH_HOUR
=
[
null
,
"
default
"
,
"
second
"
,
"
minute
"
,
"
hour
"
];
const
UNITS_WITH_DAY
=
[...
UNITS_WITH_HOUR
,
"
day
"
,
"
week
"
];
const
UNITS_WITH_HOUR
:
DatetimeUnit
[]
=
[
"
default
"
,
"
minute
"
,
"
hour
"
];
const
UNITS_WITH_DAY
:
DatetimeUnit
[]
=
[
"
default
"
,
"
minute
"
,
"
hour
"
,
"
day
"
,
"
week
"
,
];
const
UNITS_WITH_HOUR_SET
=
new
Set
(
UNITS_WITH_HOUR
);
const
UNITS_WITH_DAY_SET
=
new
Set
(
UNITS_WITH_DAY
);
export
const
hasHour
=
unit
=>
UNITS_WITH_HOUR_SET
.
has
(
unit
);
export
const
hasDay
=
unit
=>
UNITS_WITH_DAY_SET
.
has
(
unit
);
export
const
hasHour
=
(
unit
:
DatetimeUnit
)
=>
UNITS_WITH_HOUR_SET
.
has
(
unit
);
export
const
hasDay
=
(
unit
:
DatetimeUnit
)
=>
UNITS_WITH_DAY_SET
.
has
(
unit
);
export
const
DEFAULT_TIME_STYLE
=
"
h:mm A
"
;
export
const
DEFAULT_TIME_STYLE
:
TimeStyle
=
"
h:mm A
"
;
export
function
getTimeFormatFromStyle
(
style
,
unit
,
timeEnabled
)
{
export
function
getTimeFormatFromStyle
(
style
:
TimeStyle
,
unit
:
DatetimeUnit
,
timeEnabled
:
?
TimeEnabled
,
):
TimeFormat
{
let
format
=
style
;
if
(
!
timeEnabled
||
timeEnabled
===
"
milliseconds
"
)
{
return
format
.
replace
(
/mm/
,
"
mm:ss.SSS
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment