@@ -30,6 +30,42 @@ function updateAge() {
3030
3131setInterval ( updateAge , 1000 ) ;
3232
33+ // Update work periods
34+ function calculatePeriod ( startDate ) {
35+ const now = new Date ( ) ;
36+ const start = new Date ( startDate ) ;
37+ const diffTime = Math . abs ( now - start ) ;
38+ const diffDays = Math . ceil ( diffTime / ( 1000 * 60 * 60 * 24 ) ) ;
39+
40+ const years = Math . floor ( diffDays / 365 ) ;
41+ const months = Math . floor ( ( diffDays % 365 ) / 30 ) ;
42+
43+ if ( years > 0 && months > 0 ) {
44+ return `${ years } yr${ years > 1 ? 's' : '' } ${ months } mo${ months > 1 ? 's' : '' } ` ;
45+ } else if ( years > 0 ) {
46+ return `${ years } yr${ years > 1 ? 's' : '' } ` ;
47+ } else {
48+ return `${ months } mo${ months > 1 ? 's' : '' } ` ;
49+ }
50+ }
51+
52+ function updateWorkPeriods ( ) {
53+ const professorElement = document . getElementById ( "professor-period" ) ;
54+ const ctoElement = document . getElementById ( "cto-period" ) ;
55+
56+ if ( professorElement ) {
57+ professorElement . innerHTML = calculatePeriod ( new Date ( 2024 , 1 , 1 ) ) ; // Feb 2024
58+ }
59+
60+ if ( ctoElement ) {
61+ ctoElement . innerHTML = calculatePeriod ( new Date ( 2016 , 11 , 1 ) ) ; // Dec 2016
62+ }
63+ }
64+
65+ // Update periods initially and then every hour
66+ updateWorkPeriods ( ) ;
67+ setInterval ( updateWorkPeriods , 3600000 ) ; // Update every hour
68+
3369// element toggle function
3470const elementToggleFunc = function ( elem ) {
3571 elem . classList . toggle ( "active" ) ;
0 commit comments