@@ -1319,44 +1319,47 @@ <h4>Call:</h4>
1319
1319
</ script >
1320
1320
1321
1321
< script >
1322
- function calculateDuration ( start , end ) {
1323
- const [ startYear , startMonth ] = start . split ( '-' ) . map ( Number ) ;
1324
- let endDate ;
1325
-
1326
- if ( end . toLowerCase ( ) === 'present' ) {
1327
- endDate = new Date ( ) ;
1328
- } else {
1329
- const [ endYear , endMonth ] = end . split ( '-' ) . map ( Number ) ;
1330
- endDate = new Date ( endYear , endMonth - 1 ) ;
1322
+ function calculateDuration ( start , end ) {
1323
+ const [ startYear , startMonth ] = start . split ( '-' ) . map ( Number ) ;
1324
+ let endDate ;
1325
+
1326
+ if ( end . toLowerCase ( ) === 'present' ) {
1327
+ const now = new Date ( ) ;
1328
+ endDate = new Date ( now . getFullYear ( ) , now . getMonth ( ) ) ;
1329
+ } else {
1330
+ const [ endYear , endMonth ] = end . split ( '-' ) . map ( Number ) ;
1331
+ endDate = new Date ( endYear , endMonth - 1 ) ;
1332
+ }
1333
+
1334
+ const startDate = new Date ( startYear , startMonth - 1 ) ;
1335
+
1336
+ // Include both start and end month by adding 1
1337
+ let months = ( endDate . getFullYear ( ) - startDate . getFullYear ( ) ) * 12
1338
+ + ( endDate . getMonth ( ) - startDate . getMonth ( ) ) + 1 ;
1339
+
1340
+ const years = Math . floor ( months / 12 ) ;
1341
+ months = months % 12 ;
1342
+
1343
+ let result = "(" ;
1344
+ if ( years > 0 ) result += `${ years } year${ years > 1 ? 's' : '' } ` ;
1345
+ if ( years > 0 && months > 0 ) result += " " ;
1346
+ if ( months > 0 ) result += `${ months } month${ months > 1 ? 's' : '' } ` ;
1347
+ if ( years === 0 && months === 0 ) result += "less than a month" ;
1348
+ result += ")" ;
1349
+
1350
+ return result ;
1331
1351
}
1332
1352
1333
- const startDate = new Date ( startYear , startMonth - 1 ) ;
1334
- let months = ( endDate . getFullYear ( ) - startDate . getFullYear ( ) ) * 12 + ( endDate . getMonth ( ) - startDate . getMonth ( ) ) ;
1353
+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
1354
+ const durations = document . querySelectorAll ( ".duration" ) ;
1335
1355
1336
- const years = Math . floor ( months / 12 ) ;
1337
- months = months % 12 ;
1338
-
1339
- let result = "(" ;
1340
- if ( years > 0 ) result += `${ years } year${ years > 1 ? 's' : '' } ` ;
1341
- if ( years > 0 && months > 0 ) result += " " ;
1342
- if ( months > 0 ) result += `${ months } month${ months > 1 ? 's' : '' } ` ;
1343
- if ( years === 0 && months === 0 ) result += "less than a month" ;
1344
- result += ")" ;
1345
-
1346
- return result ;
1347
- }
1348
-
1349
- document . addEventListener ( "DOMContentLoaded" , ( ) => {
1350
- const durations = document . querySelectorAll ( ".duration" ) ;
1351
-
1352
- durations . forEach ( span => {
1353
- const start = span . getAttribute ( "data-start" ) ;
1354
- const end = span . getAttribute ( "data-end" ) ;
1355
- span . textContent = ` ${ calculateDuration ( start , end ) } ` ;
1356
+ durations . forEach ( span => {
1357
+ const start = span . getAttribute ( "data-start" ) ;
1358
+ const end = span . getAttribute ( "data-end" ) ;
1359
+ span . textContent = ` ${ calculateDuration ( start , end ) } ` ;
1360
+ } ) ;
1356
1361
} ) ;
1357
- } ) ;
1358
- </ script >
1359
-
1362
+ </ script >
1360
1363
<!-- ======= Mobile nav toggle button ======= -->
1361
1364
<!-- Vendor JS Files -->
1362
1365
< script src ="assets/vendor/purecounter/purecounter_vanilla.js "> </ script >
0 commit comments