Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
190b4183
Commit
190b4183
authored
Sep 26, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1121 from edx/dhm/timezone_display
Replace date lib w/ simpler tzAbbr
parents
9f93c3c2
f8cd4826
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
3 deletions
+62
-3
cms/static/js/views/settings/main_settings_view.js
+1
-2
cms/templates/settings.html
+1
-1
common/static/js/vendor/tzAbbr.js
+60
-0
No files found.
cms/static/js/views/settings/main_settings_view.js
View file @
190b4183
...
...
@@ -33,8 +33,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
$
(
this
).
show
();
});
var
dateIntrospect
=
new
Date
();
this
.
$el
.
find
(
'#timezone'
).
html
(
"("
+
dateIntrospect
.
getTimezone
()
+
")"
);
this
.
$el
.
find
(
'#timezone'
).
html
(
"("
+
tzAbbr
()
+
")"
);
this
.
listenTo
(
this
.
model
,
'invalid'
,
this
.
handleValidationError
);
this
.
listenTo
(
this
.
model
,
'change'
,
this
.
showNotificationBar
);
...
...
cms/templates/settings.html
View file @
190b4183
...
...
@@ -14,7 +14,7 @@ from contentstore import utils
<link
rel=
"stylesheet"
type=
"text/css"
href=
"${static.url('js/vendor/timepicker/jquery.timepicker.css')}"
/>
<script
src=
"${static.url('js/vendor/timepicker/jquery.timepicker.js')}"
></script>
<script
src=
"${static.url('js/vendor/timepicker/datepair.js')}"
></script>
<script
src=
"${static.url('js/vendor/
date
.js')}"
></script>
<script
src=
"${static.url('js/vendor/
tzAbbr
.js')}"
></script>
<script
type=
"text/javascript"
src=
"${static.url('js/models/course_relative.js')}"
></script>
<script
type=
"text/javascript"
src=
"${static.url('js/views/validating_view.js')}"
></script>
...
...
common/static/js/vendor/tzAbbr.js
0 → 100644
View file @
190b4183
/* Friendly timezone abbreviations in client-side JavaScript
`tzAbbr()` or `tzAbbr(new Date(79,5,24))`
=> "EDT", "CST", "GMT", etc.!
There's no 100% reliable way to get friendly timezone names in all
browsers using JS alone, but this tiny function scours a
stringified date as best it can and returns `null` in the few cases
where no friendly timezone name is found (so far, just Opera).
Device tested & works in:
* IE 6, 7, 8, and 9 (latest versions of all)
* Firefox 3 [through] 16 (16 = latest version to date)
* Chrome 22 (latest version to date)
* Safari 6 (latest version to date)
* Mobile Safari on iOS 5 & 6
* Android 4.0.3 stock browser
* Android 2.3.7 stock browser
* IE Mobile 9 (WP 7.5)
Known to fail in:
* Opera 12 (desktop, latest version to date)
For Opera, I've included (but commented out) a workaround spotted
on StackOverflow that returns a GMT offset when no abbreviation is
found. I haven't found a decent workaround.
If you find any other cases where this method returns null or dodgy
results, please say so in the comments; even if we can't find a
workaround it'll at least help others determine if this approach is
suitable for their project!
*/
var
tzAbbr
=
function
(
dateInput
)
{
var
dateObject
=
dateInput
||
new
Date
(),
dateString
=
dateObject
+
""
,
tzAbbr
=
(
// Works for the majority of modern browsers
dateString
.
match
(
/
\(([^\)]
+
)\)
$/
)
||
// IE outputs date strings in a different format:
dateString
.
match
(
/
([
A-Z
]
+
)
[\d]{4}
$/
)
);
if
(
tzAbbr
)
{
// Old Firefox uses the long timezone name (e.g., "Central
// Daylight Time" instead of "CDT")
tzAbbr
=
tzAbbr
[
1
].
match
(
/
[
A-Z
]
/g
).
join
(
""
);
}
// Uncomment these lines to return a GMT offset for browsers
// that don't include the user's zone abbreviation (e.g.,
// "GMT-0500".) I prefer to have `null` in this case, but
// you may not!
// First seen on: http://stackoverflow.com/a/12496442
// if (!tzAbbr && /(GMT\W*\d{4})/.test(dateString)) {
// return RegExp.$1;
// }
return
tzAbbr
;
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment