Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6011811
timezone.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
timezone.js
View Options
/*
* HTMLForm enhancements:
* Enable the "Fill in from browser" option for the timezone selector
*/
function
minutesToHours
(
min
)
{
const
tzHour
=
Math
.
floor
(
Math
.
abs
(
min
)
/
60
),
tzMin
=
Math
.
abs
(
min
)
%
60
,
tzString
=
(
(
min
>=
0
)
?
''
:
'-'
)
+
(
(
tzHour
<
10
)
?
'0'
:
''
)
+
tzHour
+
':'
+
(
(
tzMin
<
10
)
?
'0'
:
''
)
+
tzMin
;
return
tzString
;
}
mw
.
hook
(
'htmlform.enhance'
).
add
(
(
$root
)
=>
{
$root
.
find
(
'.mw-htmlform-timezone-field'
).
each
(
function
()
{
mw
.
loader
.
using
(
'mediawiki.widgets.SelectWithInputWidget'
,
()
=>
{
// This is identical to OO.ui.infuse( ... ), but it makes the class name of the result known.
const
timezoneWidget
=
mw
.
widgets
.
SelectWithInputWidget
.
static
.
infuse
(
$
(
this
)
);
function
maybeGuessTimezone
()
{
if
(
timezoneWidget
.
dropdowninput
.
getValue
()
!==
'guess'
)
{
return
;
}
// If available, get the named time zone from the browser.
// (We also support older browsers where this API is not available.)
let
timeZone
;
try
{
// This may return undefined
timeZone
=
Intl
.
DateTimeFormat
().
resolvedOptions
().
timeZone
;
}
catch
(
err
)
{
timeZone
=
null
;
}
// Get the time offset
const
minuteDiff
=
-
(
new
Date
().
getTimezoneOffset
()
);
let
newValue
;
if
(
timeZone
)
{
// Try to save both time zone and offset
newValue
=
'ZoneInfo|'
+
minuteDiff
+
'|'
+
timeZone
;
timezoneWidget
.
dropdowninput
.
setValue
(
newValue
);
}
if
(
!
timeZone
||
timezoneWidget
.
dropdowninput
.
getValue
()
!==
newValue
)
{
// No time zone, or it's unknown to MediaWiki. Save only offset
timezoneWidget
.
dropdowninput
.
setValue
(
'other'
);
timezoneWidget
.
textinput
.
setValue
(
minutesToHours
(
minuteDiff
)
);
}
}
timezoneWidget
.
dropdowninput
.
on
(
'change'
,
maybeGuessTimezone
);
maybeGuessTimezone
();
}
);
}
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 4 2026, 10:05 (6 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
17/0f/b3c10f8bc2ef7556f874b3d63288
Default Alt Text
timezone.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment