Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for week.js

(view source code of week.js as plain text)

  1. // Week.js,  Version 1.00 for Windows Script Host
  2. // Display the current week number.
  3. //
  4. // Written by Rob van der Woude
  5. // http://www.robvanderwoude.com
  6.  
  7. // Check command line parameters (none necessary)
  8. objArgs = WScript.Arguments;
  9. if ( objArgs.length > 0 ) Syntax( );
  10.  
  11. // Get and parse current date
  12. objToday = new Date();
  13. // Get day of month
  14. numDate  = objToday.getDate( );
  15. // Get day of week
  16. numDay   = objToday.getDay( );
  17. // Get month
  18. numMonth = objToday.getMonth( ) + 1;
  19. // Get year
  20. numYear  = objToday.getFullYear();
  21. // Check if this is a leap year
  22. isLeapYear = 0;
  23. if ( numYear %   4 == 0 ) isLeapYear = 1;
  24. if ( numYear % 100 == 0 ) isLeapYear = 0;
  25. if ( numYear % 400 == 0 ) isLeapYear = 1;
  26. // Calculate the total number of days this year
  27. numYDays = 0;
  28. if ( numMonth >  1 ) numYDays = numYDays + 31;
  29. if ( numMonth >  2 ) numYDays = numYDays + 28 + isLeapYear;
  30. if ( numMonth >  3 ) numYDays = numYDays + 31;
  31. if ( numMonth >  4 ) numYDays = numYDays + 30;
  32. if ( numMonth >  5 ) numYDays = numYDays + 31;
  33. if ( numMonth >  6 ) numYDays = numYDays + 30;
  34. if ( numMonth >  7 ) numYDays = numYDays + 31;
  35. if ( numMonth >  8 ) numYDays = numYDays + 31;
  36. if ( numMonth >  9 ) numYDays = numYDays + 30;
  37. if ( numMonth > 10 ) numYDays = numYDays + 31;
  38. if ( numMonth > 11 ) numYDays = numYDays + 30;
  39. numYDays = numYDays + numDate;
  40. // Calculate total number of days for last Sunday
  41. numYDays = numYDays - numDay;
  42. // Integer divide by 7 to get the number of whole weeks
  43. numWeek = ( numYDays - ( numYDays % 7 ) ) / 7;
  44. // Minimum number of days in week 1
  45. numMinDWeek1 = 4;
  46. if ( ( numYDays ) % 7 > numMinDWeek1 ) numWeek = numWeek + 1;
  47. // Show the results
  48. WScript.Echo( "Week=" + numWeek );
  49. // Quit and return week number
  50. WScript.Quit( numWeek );
  51.  
  52.  
  53. function Syntax( ) {
  54. WScript.Echo( );
  55. WScript.Echo( "Week.js,  Version 1.00 for WSH" );
  56. WScript.Echo( "Display the current week number." );
  57. WScript.Echo( );
  58. WScript.Echo( "Usage:   CScript  WEEK.JS" );
  59. WScript.Echo( );
  60. WScript.Echo( "Returns: current week number" );
  61. WScript.Echo( "         or 255 on syntax errors" );
  62. WScript.Echo( );
  63. WScript.Echo( "Assumptions: [1] First day of the week is Sunday" );
  64. WScript.Echo( "             [2] Week 1 is the first week of the year with at least 4 days" );
  65. WScript.Echo( "These assumptions can be changed by modifying the script's source code." );
  66. WScript.Echo( "Read the comments in the source code to find the values to be modified." );
  67. WScript.Echo( );
  68. WScript.Echo( "Written by Rob van der Woude" );
  69. WScript.Echo( "http://www.robvanderwoude.com" );
  70. WScript.Quit(255);
  71. }
  72.  

page last modified: 2024-04-16; loaded in 0.0065 seconds