@@ -30,6 +30,45 @@ 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+ let result = "" ;
44+ if ( years > 0 ) {
45+ result += `${ years } yr${ years > 1 ? "s" : "" } ` ;
46+ }
47+ if ( months > 0 ) {
48+ if ( result ) result += " " ;
49+ result += `${ months } mo${ months > 1 ? "s" : "" } ` ;
50+ }
51+
52+ return result || "0 mos" ;
53+ }
54+
55+ function updateWorkPeriods ( ) {
56+ const professorElement = document . getElementById ( "professor-period" ) ;
57+ const ctoElement = document . getElementById ( "cto-period" ) ;
58+
59+ if ( professorElement ) {
60+ professorElement . innerHTML = calculatePeriod ( new Date ( 2024 , 1 , 1 ) ) ; // Feb 2024
61+ }
62+
63+ if ( ctoElement ) {
64+ ctoElement . innerHTML = calculatePeriod ( new Date ( 2016 , 11 , 1 ) ) ; // Dec 2016
65+ }
66+ }
67+
68+ // Update periods initially and then every hour
69+ updateWorkPeriods ( ) ;
70+ setInterval ( updateWorkPeriods , 3600000 ) ; // Update every hour
71+
3372// element toggle function
3473const elementToggleFunc = function ( elem ) {
3574 elem . classList . toggle ( "active" ) ;
0 commit comments