Advertisement
Guest User

sakila_dw.js

a guest
Nov 20th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Create a Locale according to the specified language code
  2. var locale = new java.util.Locale(
  3. language_code.getString()
  4. , country_code.getString()
  5. );
  6. //Create a calendar, use the specified initial date
  7.  
  8. 69
  9. var calendar = new java.util.GregorianCalendar(locale);
  10. calendar.setTime(initial_date.getDate());
  11. //set the calendar to the current date by adding DaySequence
  12. days
  13. calendar.add(calendar.DAY_OF_MONTH,DaySequence.getInteger()
  14. - 1);
  15. //get the calendar date
  16. var date = new java.util.Date(calendar.getTimeInMillis());
  17. //en-us example: 9/3/07
  18. var date_short = java.text.DateFormat.getDateInstance(
  19. java.text.DateFormat.SHORT
  20. , locale
  21. ).format(date);
  22. //en-us example: Sep 3, 2007
  23. var date_medium = java.text.DateFormat.getDateInstance(
  24. java.text.DateFormat.MEDIUM
  25. , locale
  26. ).format(date);
  27. //en-us example: September 3, 2007
  28. var date_long = java.text.DateFormat.getDateInstance(
  29. java.text.DateFormat.LONG
  30. , locale
  31. ).format(date);
  32. //en-us example: Monday, September 3, 2007
  33. var date_full = java.text.DateFormat.getDateInstance(
  34. java.text.DateFormat.FULL
  35. , locale
  36. ).format(date);
  37. //day in year: 1..366
  38. var simpleDateFormat =
  39. java.text.SimpleDateFormat("D",locale);
  40. var day_in_year = simpleDateFormat.format(date);
  41. //day in month: 1..31
  42. simpleDateFormat.applyPattern("d");
  43. var day_in_month = simpleDateFormat.format(date);
  44. //en-us example: "Monday"
  45. simpleDateFormat.applyPattern("EEEE");
  46. var day_name = simpleDateFormat.format(date);
  47. //en-us example: "Mon"
  48. simpleDateFormat.applyPattern("E");
  49. var day_abbreviation = simpleDateFormat.format(date);
  50. //week in year, 1..53
  51. simpleDateFormat.applyPattern("ww");
  52. var week_in_year = simpleDateFormat.format(date);
  53. //week in month, 1..5
  54. simpleDateFormat.applyPattern("W");
  55. var week_in_month = simpleDateFormat.format(date);
  56. //month number in year, 1..12
  57. simpleDateFormat.applyPattern("MM");
  58. var month_number = simpleDateFormat.format(date);
  59. //en-us example: "September"
  60. simpleDateFormat.applyPattern("MMMM");
  61. var month_name = simpleDateFormat.format(date);
  62.  
  63. 70
  64. //en-us example: "Sep"
  65. simpleDateFormat.applyPattern("MMM");
  66. var month_abbreviation = simpleDateFormat.format(date);
  67. //2 digit representation of the year, example: "07" for 2007
  68. simpleDateFormat.applyPattern("y");
  69. var year2 = simpleDateFormat.format(date);
  70. //4 digit representation of the year, example: 2007
  71. simpleDateFormat.applyPattern("yyyy");
  72. var year4 = "" + simpleDateFormat.format(date);
  73. //handling Quarters is a DIY
  74. var quarter_name = "Q";
  75. var quarter_number;
  76. switch(parseInt(month_number)){
  77. case 1: case 2: case 3: quarter_number = "1"; break;
  78. case 4: case 5: case 6: quarter_number = "2"; break;
  79. case 7: case 8: case 9: quarter_number = "3"; break;
  80. case 10: case 11: case 12: quarter_number = "4"; break;
  81. }
  82. quarter_name += quarter_number;
  83. //get the local yes/no values
  84. var yes = local_yes.getString();
  85. var no = local_no.getString();
  86. //initialize for week calculations
  87. var first_day_of_week = calendar.getFirstDayOfWeek();
  88. var day_of_week = java.util.Calendar.DAY_OF_WEEK;
  89. //find out if this is the first day of the week
  90. var is_first_day_in_week;
  91. if(first_day_of_week==calendar.get(day_of_week)){
  92. is_first_day_in_week = yes;
  93. } else {
  94. is_first_day_in_week = no;
  95. }
  96. //calculate the next day
  97. calendar.add(calendar.DAY_OF_MONTH,1);
  98. //get the next calendar date
  99. var next_day = new
  100. java.util.Date(calendar.getTimeInMillis());
  101. //find out if this is the first day of the week
  102. var is_last_day_in_week;
  103. if(first_day_of_week==calendar.get(day_of_week)){
  104. is_last_day_in_week = yes;
  105. } else {
  106. is_last_day_in_week = no;
  107. }
  108. //find out if this is the first day of the month
  109. var is_first_day_of_month;
  110. if(day_in_month == 1){
  111. is_first_day_in_month = yes;
  112. } else {
  113. is_first_day_in_month = no;
  114.  
  115. 71
  116. }
  117. //find out if this is the last day in the month
  118. var is_last_day_of_month;
  119. if(java.text.SimpleDateFormat("d",locale).format(next_day)==
  120. 1){
  121. is_last_day_in_month = yes;
  122. } else {
  123. is_last_day_in_month = no;
  124. }
  125. //date = year4 + "-" + month_number + "-" + day_in_month
  126. var year_quarter = year4 + "-" + quarter_name;
  127. var year_month_number = year4 + "-" + month_number;
  128. var year_month_abbreviation = year4 + "-" +
  129. month_abbreviation;
  130. var date_key = year4 + month_number +
  131. (day_in_month<10?"0":"") + day_in_month;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement