Team:KULeuven/Tools/New Day/Date Retriever
From 2008.igem.org
(Difference between revisions)
m |
|||
Line 1: | Line 1: | ||
<html> | <html> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
+ | |||
+ | var pageDate; | ||
var mnames = new Array('January', 'February', 'March', 'April', 'May', | var mnames = new Array('January', 'February', 'March', 'April', 'May', | ||
'June', 'July', 'August', 'September', 'October', 'November', 'December'); | 'June', 'July', 'August', 'September', 'October', 'November', 'December'); | ||
Line 6: | Line 8: | ||
var dnames = new Array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); | var dnames = new Array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); | ||
- | function | + | /* Extracts the corresponding calendar date out of the page url */ |
- | // | + | function pageDate() { |
- | var | + | // Retrieve page url |
- | + | var urlTokens = location.href.split("/"); | |
- | var | + | var urlLast = urlTokens[urlTokens.length - 1]; |
- | var | + | // Retrieve page date |
- | var | + | var wikiTokens = urlLast.split("#"); |
+ | var wikiFirst = wikiTokens[0]; | ||
- | var | + | // Retrieve seperate date components |
- | + | var dateTokens = wikiFirst.split("_"); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | var day = dateTokens[0]; | |
- | + | var month = dateTokens[1]; | |
- | var | + | var year = dateTokens[2]; |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | // Construct a Date object and return the result | |
- | + | return (new Date()).setFullYear(year, month, day); | |
+ | } | ||
- | return | + | /* Retrieves date ndays before this page date */ |
+ | function datePast(ndays) { | ||
+ | var pastDate = new Date(); | ||
+ | pastDate.setDate(pageDate.getDate() - days); | ||
+ | return pageDate; | ||
} | } | ||
- | function | + | /* Searches date ndays after this page date */ |
- | var | + | function dateFuture(ndays) { |
+ | var futureDate = new Date(); | ||
+ | futureDate.setDate(pageDate.getDate() + days); | ||
+ | return futureDays; | ||
+ | } | ||
- | var | + | /* Returns the date of Friday previous week */ |
- | + | function previousWeekFriday() { | |
+ | var dayOfWeek = pageDate.getDay(); | ||
+ | var previousWeekFriday; | ||
- | + | switch(dayOfWeek) { | |
- | switch( | + | case 0: previousWeekFriday.setDate(pageDate.getDate() - 9); break; |
- | + | default: previousWeekFriday.setDate(pageDate.getDate() - (dayOfWeek + 2)); | |
- | case 0: | + | |
- | default: | + | |
} | } | ||
- | + | return previousWeekFriday; | |
- | + | ||
- | return | + | |
} | } | ||
- | function | + | /* Returns the date of Monday next week */ |
- | var | + | function nextWeekMonday() { |
+ | var dayOfWeek = pageDate.getDay(); | ||
+ | var nextWeekMonday; | ||
- | + | switch(dayOfWeek) { | |
- | + | case 0: nextWeekMonday.setDate(pageDate.getDate() + 1); break; | |
- | + | default: nextWeekMonday.setDate(pageDate.getDate() + (8 - dayOfWeek)); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | default: | + | |
} | } | ||
- | + | return nextWeekMonday; | |
- | + | ||
- | return | + | |
} | } | ||
- | function | + | /* Returns the date of Friday this week */ |
- | var | + | function thisFriday() { |
- | + | var dayOfWeek = pageDate.getDay(); | |
- | + | var thisFriday; | |
- | + | ||
- | + | switch(dayOfWeek) { | |
- | + | case 0: thisFriday.setDate(pageDate.getDate() - 2); break; | |
+ | case 6: thisFriday.setDate(pageDate.getDate() - 1); break; | ||
+ | default: thisFriday.setDate(pageDate.getDate() + (5 - dayOfWeek)); | ||
+ | } | ||
+ | |||
+ | return thisFriday; | ||
+ | } | ||
- | window.location.href= | + | /* Converts a date into a valid url for the KULeuven wiki and loads the page */ |
+ | function goToDate(date) { | ||
+ | var URL = "https://2008.igem.org/Team:KULeuven/"; | ||
+ | URL += date.getDate(); | ||
+ | URL += '_'; | ||
+ | URL += monthNames[date.getMonth()]; | ||
+ | URL += '_'; | ||
+ | URL += date.getFullYear(); | ||
+ | window.location.href = URL; | ||
} | } | ||
</script> | </script> | ||
Line 95: | Line 104: | ||
</tr> | </tr> | ||
<tr align="center"> | <tr align="center"> | ||
- | <td align="left" width="25%"><a href="javascript:void(0);" onClick=" | + | <td align="left" width="25%"><a href="javascript:void(0);" onClick="goToDate(previousWeekFriday());">< previous friday</a></td> |
- | <td width="25%"><a href="javascript:void(0);" onClick=" | + | <td width="25%"><a href="javascript:void(0);" onClick="goToDate(datePast(1));">← yesterday</a></td> |
- | <td width="25%"><a href="javascript:void(0);" onClick=" | + | <td width="25%"><a href="javascript:void(0);" onClick="goToDate(dateFuture(1));">tomorrow →</a></td> |
- | <td align="right" width="25%"><a href="javascript:void(0);" onClick=" | + | <td align="right" width="25%"><a href="javascript:void(0);" onClick="goToDate(nextWeekMonday());">next monday ></a></td> |
</tr> | </tr> | ||
</table> | </table> |
Revision as of 09:11, 31 July 2008
<< return to notebook | return to homepage >> | ||
< previous friday | ← yesterday | tomorrow → | next monday > |