Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Systems Frontend
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Motion Bank
Applications
Systems Frontend
Merge requests
!261
using consts instead of an object
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
using consts instead of an object
877-time-functions-reuse
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Böhm, Jean
requested to merge
877-time-functions-reuse
into
master
3 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#877 (closed)
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
61a14e45
1 commit,
3 years ago
1 file
+
107
−
90
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/boot/time.js
+
107
−
90
Options
@@ -2,14 +2,12 @@ import Vue from 'vue'
import
{
DateTime
}
from
'
luxon
'
import
qs
from
'
qs
'
// Description
// prefixes:
// get => returns something to work with (obj, iso etc.)
// display => formats dates and time to be displayed in the interface
export
default
({
app
})
=>
{
// Preset for displaying milliseconds
// Preset for displaying milliseconds
const
DATETIME_PRESET_FORMAT
=
{
year
:
'
numeric
'
,
month
:
'
short
'
,
@@ -20,97 +18,116 @@ export default ({ app }) => {
fractionalSecondDigits
:
3
}
Vue
.
prototype
.
$time
=
{
// helpers for q-input -----------------------------------------------------------------------------------------------
getInputTimeFromISO
:
(
isoString
)
=>
{
DateTime
.
fromISO
(
isoString
).
toFormat
(
'
TT.SSS
'
)
},
getInputDateFromISO
:
(
isoString
)
=>
{
return
DateTime
.
fromISO
(
isoString
).
toFormat
(
'
y-LL-dd
'
)
},
getInputTimeFromQuery
:
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
).
toFormat
(
'
TT.SSS
'
)
},
getInputDateFromQuery
:
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
).
toFormat
(
'
y-LL-dd
'
)
},
getInputCurrentDate
:
()
=>
{
return
DateTime
.
local
().
toFormat
(
'
y-LL-dd
'
)
},
getInputCurrentTime
:
()
=>
{
return
DateTime
.
local
().
toFormat
(
'
TT.SSS
'
)
},
inputTimeAndDateToQuery
:
(
time
,
date
)
=>
{
const
combined
=
DateTime
.
fromISO
(
`
${
date
}
T
${
time
}
`
)
return
{
'
date-time:t
'
:
combined
.
toLocal
().
toISO
()
}
},
inputTimeAndDateToISO
:
(
time
,
date
)
=>
{
return
DateTime
.
fromISO
(
`
${
date
}
T
${
time
}
`
).
toLocal
().
toISO
()
},
// helpers for q-input -----------------------------------------------------------------------------------------------
const
getInputTimeFromISO
=
(
isoString
)
=>
{
DateTime
.
fromISO
(
isoString
).
toFormat
(
'
TT.SSS
'
)
}
const
getInputDateFromISO
=
(
isoString
)
=>
{
return
DateTime
.
fromISO
(
isoString
).
toFormat
(
'
y-LL-dd
'
)
}
const
getInputTimeFromQuery
=
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
).
toFormat
(
'
TT.SSS
'
)
}
const
getInputDateFromQuery
=
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
).
toFormat
(
'
y-LL-dd
'
)
}
const
getInputCurrentDate
=
()
=>
{
return
DateTime
.
local
().
toFormat
(
'
y-LL-dd
'
)
}
const
getInputCurrentTime
=
()
=>
{
return
DateTime
.
local
().
toFormat
(
'
TT.SSS
'
)
}
const
inputTimeAndDateToQuery
=
(
time
,
date
)
=>
{
const
combined
=
DateTime
.
fromISO
(
`
${
date
}
T
${
time
}
`
)
return
{
'
date-time:t
'
:
combined
.
toLocal
().
toISO
()
}
}
const
inputTimeAndDateToISO
=
(
time
,
date
)
=>
{
return
DateTime
.
fromISO
(
`
${
date
}
T
${
time
}
`
).
toLocal
().
toISO
()
}
// Current times getters ---------------------------------------------------------------------------------------------
getCurrentDateTime
:
()
=>
{
return
DateTime
.
local
()
}
,
getCurrentDateTimeISO
:
()
=>
{
return
DateTime
.
local
().
toISO
()
}
,
// Current times getters ---------------------------------------------------------------------------------------------
const
getCurrentDateTime
=
()
=>
{
return
DateTime
.
local
()
}
const
getCurrentDateTimeISO
=
()
=>
{
return
DateTime
.
local
().
toISO
()
}
// Helpers for parsing time query from API ---------------------------------------------------------------------------
getDateTimeFromQuery
:
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
)
}
,
getISOFromQuery
:
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
parsed
[
'
date-time:t
'
]
}
,
displayTimeQuery
:
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
).
toLocaleString
(
DATETIME_PRESET_FORMAT
)
}
,
// Helpers for parsing time query from API ---------------------------------------------------------------------------
const
getDateTimeFromQuery
=
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
)
}
const
getISOFromQuery
=
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
parsed
[
'
date-time:t
'
]
}
const
displayTimeQuery
=
(
queryString
)
=>
{
const
parsed
=
qs
.
parse
(
queryString
,
{
decoder
:
val
=>
val
})
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}
).
toLocaleString
(
DATETIME_PRESET_FORMAT
)
}
// Helper to display ISO time ----------------------------------------------------------------------------------------
displayTimeISO
:
(
isoString
)
=>
{
return
DateTime
.
fromISO
(
isoString
,
{
setZone
:
true
}
).
toLocaleString
(
DATETIME_PRESET_FORMAT
)
}
,
displayISODaysAgo
(
isoString
)
{
const
past
=
DateTime
.
fromISO
(
isoString
)
return
past
.
toRelativeCalendar
({
locale
:
app
.
i18n
.
locale
})
}
,
// Helper to display ISO time ----------------------------------------------------------------------------------------
const
displayTimeISO
=
(
isoString
)
=>
{
return
DateTime
.
fromISO
(
isoString
,
{
setZone
:
true
}
).
toLocaleString
(
DATETIME_PRESET_FORMAT
)
}
const
displayISODaysAgo
=
(
isoString
)
=>
{
const
past
=
DateTime
.
fromISO
(
isoString
)
return
past
.
toRelativeCalendar
({
locale
:
app
.
i18n
.
locale
})
}
// Helper to display Millis time -----------------------------------------------------------------------------------
displayTimeFromMillis
:
(
millisString
)
=>
{
return
DateTime
.
fromMillis
(
millisString
,
{
setZone
:
true
}
).
toLocaleString
(
DATETIME_PRESET_FORMAT
)
},
isoToMillis
:
(
iso
)
=>
{
return
DateTime
.
fromISO
(
iso
,
{
setZone
:
true
}).
toMillis
()
},
millisFromQuery
:
(
query
)
=>
{
const
parsed
=
qs
.
parse
(
query
,
{
decoder
:
val
=>
val
})
if
(
typeof
parsed
[
'
date-time:t
'
]
===
'
string
'
)
{
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}).
toMillis
()
}
// Helper to display Millis time -----------------------------------------------------------------------------------
const
displayTimeFromMillis
=
(
millisString
)
=>
{
return
DateTime
.
fromMillis
(
millisString
,
{
setZone
:
true
}
).
toLocaleString
(
DATETIME_PRESET_FORMAT
)
}
const
isoToMillis
=
(
iso
)
=>
{
return
DateTime
.
fromISO
(
iso
,
{
setZone
:
true
}).
toMillis
()
}
const
millisFromQuery
=
(
query
)
=>
{
const
parsed
=
qs
.
parse
(
query
,
{
decoder
:
val
=>
val
})
if
(
typeof
parsed
[
'
date-time:t
'
]
===
'
string
'
)
{
return
DateTime
.
fromISO
(
parsed
[
'
date-time:t
'
],
{
setZone
:
true
}).
toMillis
()
}
}
Vue
.
prototype
.
$time
=
{
getInputTimeFromISO
,
getInputDateFromISO
,
getInputTimeFromQuery
,
getInputDateFromQuery
,
getInputCurrentDate
,
getInputCurrentTime
,
inputTimeAndDateToQuery
,
inputTimeAndDateToISO
,
getCurrentDateTime
,
getCurrentDateTimeISO
,
getDateTimeFromQuery
,
getISOFromQuery
,
displayTimeQuery
,
displayTimeISO
,
displayISODaysAgo
,
displayTimeFromMillis
,
isoToMillis
,
millisFromQuery
}
}
Loading