PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/timezone.coffee

https://gitlab.com/gpinela/coipo
CoffeeScript | 123 lines | 68 code | 20 blank | 35 comment | 27 complexity | 9366b97515121776ef6ac74b05d8f30b MD5 | raw file
  1. # Description:
  2. # Cuanto falta
  3. #
  4. # Dependencies:
  5. # None
  6. #
  7. # Configuration:
  8. # None
  9. #
  10. # Commands:
  11. # hubot que hora
  12. # hubot la hora
  13. #
  14. # Author:
  15. # @jorgeepunan
  16. module.exports = (robot) ->
  17. robot.respond /(.*)(qu[] hora|la hora.*)/i, (msg) ->
  18. #from DayTimr.js
  19. #https://github.com/juanbrujo/daytimr/blob/master/js/jquery.dayTimr-1.0.js
  20. nightStart = '19:00'
  21. dawnStart = '1:00'
  22. morningStart = '7:00'
  23. afternoonStart = '13:00'
  24. days = ['domingo','lunes','martes','miércoles','jueves','viernes','sábado']
  25. datetoday = new Date()
  26. timenow = datetoday.getTime()
  27. datetoday.setTime(timenow)
  28. theday = days[datetoday.getDay()]
  29. thehour = datetoday.getHours()
  30. theminute = datetoday.getMinutes()
  31. thesecond = datetoday.getSeconds()
  32. nightStart = nightStart.split(':')
  33. nightStartH = nightStart[0]
  34. nightStartM = nightStart[1]
  35. dawnStart = dawnStart.split(':')
  36. dawnStartH = dawnStart[0]
  37. dawnStartM = dawnStart[1]
  38. morningStart = morningStart.split(':')
  39. morningStartH = morningStart[0]
  40. morningStartM = morningStart[1]
  41. afternoonStart = afternoonStart.split(':')
  42. afternoonStartH = afternoonStart[0]
  43. afternoonStartM = afternoonStart[1]
  44. nightEndH = dawnStartH-1
  45. dawnEndH = morningStartH-1
  46. morningEndH = afternoonStartH-1
  47. afternoonEndH = nightStartH-1
  48. if nightStartH == 0
  49. afternoonEndH = 23
  50. if dawnStartH == 0
  51. nightEndH = 23
  52. if nightStartM == "00" or dawnStartM == "00" or morningStartM == "00" or afternoonStartM == "00"
  53. nightEndM = 59
  54. dawnEndM = 59
  55. morningEndM = 59
  56. afternoonEndM = 59
  57. if theminute < 10
  58. theminute = '0' + theminute
  59. #msg.send "Current Time: "+thehour+':'+theminute+':'+thesecond
  60. #msg.send "It's night from "+nightStartH+":"+nightStartM+" to "+nightEndH+":"+nightEndM
  61. #msg.send "It's dawn from "+dawnStartH+":"+dawnStartM+" to "+dawnEndH+":"+dawnEndM
  62. #msg.send "It's morning from "+morningStartH+":"+morningStartM+" to "+morningEndH+":"+morningEndM
  63. #msg.send "It's afternoon from "+afternoonStartH+":"+afternoonStartM+" to "+afternoonEndH+":"+afternoonEndM
  64. if theday == 'sábado'
  65. #NIGHT
  66. if thehour >= nightStartH and theminute >= nightStartM and thesecond <= 59 and thehour <= nightEndH and theminute <= nightEndM and thesecond >= 0
  67. msg.send "Son las " + thehour + ":" + theminute + "y es " + theday + ". ¡Hora de parrandear!"
  68. #DAWN
  69. if thehour >= dawnStartH and theminute >= dawnStartM and thesecond <= 59 and thehour <= dawnEndH and theminute <= dawnEndM and thesecond >= 0
  70. msg.send "Ya es " + theday + " y de madrugada " + thehour + ":" + theminute + ". Trata en volver a casa sano y salvo."
  71. #MORNING
  72. if thehour >= morningStartH and theminute >= morningStartM and thesecond <= 59 and thehour <= morningEndH and theminute <= morningEndM and thesecond >= 0
  73. msg.send "Son las " + thehour + ":" + theminute + " del " + theday + ", vuelve a dormir."
  74. #TARDE
  75. if thehour >= afternoonStartH and theminute >= afternoonStartM and thesecond <= 59 and thehour <= afternoonEndH and theminute <= afternoonEndM and thesecond >= 0
  76. msg.send "Son las " + thehour + ":" + theminute + " de un " + theday + ", junta sed que ya se viene el carrete."
  77. else if theday == 'domingo'
  78. #NIGHT
  79. if thehour >= nightStartH and theminute >= nightStartM and thesecond <= 59 and thehour <= nightEndH and theminute <= nightEndM and thesecond >= 0
  80. msg.send "Es " + theday " y son las " + thehour + ":" + theminute + ", a preparar la semana."
  81. #DAWN
  82. if thehour >= dawnStartH and theminute >= dawnStartM and thesecond <= 59 and thehour <= dawnEndH and theminute <= dawnEndM and thesecond >= 0
  83. msg.send "Es " + theday + " " + thehour + ":" + theminute + " de madrugada. Vuelve a intentar dormir."
  84. #MORNING
  85. if thehour >= morningStartH and theminute >= morningStartM and thesecond <= 59 and thehour <= morningEndH and theminute <= morningEndM and thesecond >= 0
  86. msg.send "Son las " + thehour + ":" + theminute + " del " + theday + ", es mañana aún."
  87. #TARDE
  88. if thehour >= afternoonStartH and theminute >= afternoonStartM and thesecond <= 59 and thehour <= afternoonEndH and theminute <= afternoonEndM and thesecond >= 0
  89. msg.send "Son las " + thehour + ":" + theminute + " y es " + theday + ", tómate una siesta."
  90. else
  91. #NIGHT
  92. if thehour >= nightStartH and theminute >= nightStartM and thesecond <= 59 and thehour <= nightEndH and theminute <= nightEndM and thesecond >= 0
  93. msg.send "Es hora de beber, ya son las " + thehour + ":" + theminute + "de un " + theday
  94. #DAWN
  95. if thehour >= dawnStartH and theminute >= dawnStartM and thesecond <= 59 and thehour <= dawnEndH and theminute <= dawnEndM and thesecond >= 0
  96. msg.send "Es madrugada del " + theday + " y son las " + thehour + ":" + theminute + ". Vuelve a intentar dormir."
  97. #MORNING
  98. if thehour >= morningStartH and theminute >= morningStartM and thesecond <= 59 and thehour <= morningEndH and theminute <= morningEndM and thesecond >= 0
  99. msg.send "Son las " + thehour + ":" + theminute + " del " + theday + ", es mañana aún."
  100. #TARDE
  101. if thehour >= afternoonStartH and theminute >= afternoonStartM and thesecond <= 59 and thehour <= afternoonEndH and theminute <= afternoonEndM and thesecond >= 0
  102. msg.send "Son las " + thehour + ":" + theminute + " y es " + theday + ", queda menos para salir del trabajo."
  103. #FIN