MCPcopy Create free account
hub / github.com/apache/cloudstack / toLocaleDate

Function toLocaleDate

ui/src/utils/date.js:78–102  ·  view source on GitHub ↗
({ date, timezoneoffset = store.getters.timezoneoffset, usebrowsertimezone = store.getters.usebrowsertimezone, dateOnly = false, hourOnly = false })

Source from the content-addressed store, hash-verified

76}
77
78export function toLocaleDate ({ date, timezoneoffset = store.getters.timezoneoffset, usebrowsertimezone = store.getters.usebrowsertimezone, dateOnly = false, hourOnly = false }) {
79 if (!date) {
80 return null
81 }
82
83 let dateWithOffset = toLocalDate({ date, timezoneoffset, usebrowsertimezone }).toUTCString()
84
85 // e.g. "Mon, 03 Jun 2024 19:22:55 GMT" -> "03 Jun 2024 19:22:55 GMT"
86 dateWithOffset = dateWithOffset.substring(dateWithOffset.indexOf(', ') + 2)
87
88 // e.g. "03 Jun 2024 19:22:55 GMT" -> "03 Jun 2024 19:22:55"
89 dateWithOffset = dateWithOffset.substring(0, dateWithOffset.length - 4)
90
91 if (dateOnly) {
92 // e.g. "03 Jun 2024 19:22:55" -> "03 Jun 2024"
93 return dateWithOffset.substring(0, dateWithOffset.length - 9)
94 }
95
96 if (hourOnly) {
97 // e.g. "03 Jun 2024 19:22:55" -> "19:22:55"
98 return dateWithOffset.substring(dateWithOffset.length - 8, dateWithOffset.length)
99 }
100
101 return dateWithOffset
102}
103
104export { dayjs }

Callers 1

installFunction · 0.90

Calls 1

toLocalDateFunction · 0.85

Tested by

no test coverage detected