Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Timezones #12

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d3d722b
remove extraneous </html>
MoralCode Dec 29, 2018
c21b292
add schoolIsInSession() function
MoralCode Dec 29, 2018
f168fb6
add state flags
MoralCode Dec 29, 2018
426c81b
remove passing periods from the schedule
MoralCode Dec 29, 2018
76a8b68
re-organise updateText using state flags
MoralCode Dec 29, 2018
a0af5a6
continue to update the time even if schedule data is not available
MoralCode Jan 1, 2019
bd0c146
Add flash function
MoralCode Jan 2, 2019
53d8eea
Change data structure to support multiple hardcoded schools
MoralCode Jan 31, 2019
4a608cf
add function to get an index from localStorage
MoralCode Jan 31, 2019
437b16d
Add School Name
MoralCode Jan 2, 2019
d775a8b
fix close spacing on settings page
MoralCode Jan 2, 2019
5fde3c6
continue to update date and time even if a school isn't selected
MoralCode Jan 2, 2019
516b99e
move nav button HTML to a more sensible place
MoralCode Jan 2, 2019
2249dd7
group elements that are schedule-based together for easier hiding
MoralCode Jan 2, 2019
e8fec35
hide schedule-based elements when there is no schedule selected
MoralCode Jan 2, 2019
cfac59c
move flash messages above the whole page rather than over the top of it
MoralCode Jan 2, 2019
e037d9e
Documentation and cleanup
MoralCode Jan 2, 2019
cc3af4a
fix flashing so that the layouts dont break on mobile
MoralCode Jan 2, 2019
12eedae
add school name to summary for clarity
MoralCode Jan 2, 2019
5fcc0fa
add slack link instead of github issues link
MoralCode Jan 2, 2019
5c2188c
Add a tracking metric for the school someone has selected
MoralCode Jan 2, 2019
9cae0b8
Move "View Schedule" link
MoralCode Jan 2, 2019
5cfa996
re-configure display of school name on homepage
MoralCode Jan 2, 2019
359ff24
fix flash messages taking up half the screen sometimes
MoralCode Jan 2, 2019
a7eb69c
add tracking for usage of time display setting
MoralCode Jan 2, 2019
96eadf6
refactor getClassName()
MoralCode Jan 5, 2019
d3a8978
replace time globals with a method to get the current time object
MoralCode Feb 1, 2019
8a7fdbf
add proper time comparison methods
MoralCode Feb 1, 2019
7ad2861
implement new time methods
MoralCode Feb 1, 2019
8bfd994
fix centered links extending all the way across the page
MoralCode Feb 3, 2019
c1d7049
fix missing "...which ends in:" data on main page
MoralCode Feb 3, 2019
2c66a1f
refactor compareTimes() to include minutes in it's calculation
MoralCode Feb 7, 2019
2e07244
Add sanitizeTimeObject()
MoralCode Feb 7, 2019
f424879
add getMostRecentlyStartedClassIndex()
MoralCode Feb 7, 2019
854c7ea
make getTimeDelta() more flexible
MoralCode Feb 7, 2019
d9878b4
samitize times before comparing them so it doesnt skip seconds
MoralCode Feb 7, 2019
50a3ba1
add passing period name to school data
MoralCode Feb 7, 2019
3b358a2
add getTimeTo() shortcut
MoralCode Feb 7, 2019
db6d769
remove getTimeToEndOfCurrentClassString() and getTimeToStartOfSchoolS…
MoralCode Feb 7, 2019
ce25c98
update documentation and comments
MoralCode Feb 7, 2019
00893bf
replace tracking code with matomo tag manager
MoralCode Feb 7, 2019
6bfbc2b
hide labels on no school days
MoralCode Feb 10, 2019
6b485dd
add styles for links in flash messages
MoralCode Feb 10, 2019
1f49a7a
remove links from readme
MoralCode Feb 10, 2019
97e7ab5
update domain name on dev branch
MoralCode Feb 13, 2019
f611fc0
fix an instance of the old name
MoralCode Feb 14, 2019
0ae2bd8
Update README file
MoralCode Feb 14, 2019
4c37921
Add support for Timezones.
Feb 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions classtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ var currentClassPeriodIndex = -1;
var currentScheduleIndex = -1;
var selectedSchoolIndex = 0;


var use24HourTime = getLocalStorageBoolean("use24HourTime", false);



var schools = [
{
fullName: "Lake Oswego High School",
shortName: "LOHS",
passingPeriodName: "Passing Period", //the name to use for time gaps in the schedule between classes
//order is as is on the school website, although it doesnt matter.
timeZone: 'America/Los_Angeles',
schedules: [
{
name: "Mon/Fri (Regular)",
Expand Down Expand Up @@ -305,23 +303,29 @@ function isNoSchoolDay() {
/**
* This function updates the variables that keep track of the current time and date
*/
function updateTime() { currentDate = new Date();}
function updateTime() {
if (typeof selectedSchoolIndex !== 'undefined') {
currentDate = moment().tz(schools[selectedSchoolIndex].timeZone);
} else {
currentDate = moment()
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the updateTime() method is intended for updating the time in general (i.e. for the local time clock). I think it would be better to use moment to convert to and from GMT when storing and retrieving the times

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, if i'm understanding this correctly, I think this might show the local time at the school instead of the users local time if there is a school selected


function getCurrentTimeObject() {
return {hours: currentDate.getHours(), minutes: currentDate.getMinutes(), seconds: currentDate.getSeconds()}
return {hours: currentDate.hour(), minutes: currentDate.minute(), seconds: currentDate.second()}
}


/**
* @returns the current time as a formatted string
*/
function getCurrentTimeString() { return currentDate.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: !use24HourTime }) }
function getCurrentTimeString() { return use24HourTime ? currentDate.format("h:mm:ss a") : currentDate.format("H:mm:ss") }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have the 12 and 24 hour conditions reversed here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, i think AM/PM should be capitalized


/**
* @returns the current date as a formatted string
*/
function getCurrentDateString() {
return "on <strong>" + currentDate.toLocaleString('en-US', { weekday: 'short', month: 'short', day: 'numeric', year: 'numeric' }) + "</strong>"
return "on <strong>" + currentDate.format("ddd, MMM Do, YYYY") + "</strong>"
}

/**
Expand Down Expand Up @@ -389,7 +393,7 @@ function getMostRecentlyStartedClassIndex() {
function getCurrentScheduleIndex() {
//using for over forEach() because we are breaking out of the loop early
for (let i = 0; i < schools[selectedSchoolIndex].schedules.length; i++) {
if (schools[selectedSchoolIndex].schedules[i].days.includes(currentDate.getDay())) {
if (schools[selectedSchoolIndex].schedules[i].days.includes(currentDate.day())) {
return i
}
}
Expand Down
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ <h1 class="centered bottomSpace" id="nextClass"></h1>
}
}

</script>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data-2012-2022.js"></script>