Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #pragma once
  2. #include <string>
  3. #include <time.h>
  4. #include <ctime>
  5. #include <iostream>
  6.  
  7.  
  8. class Calendar {
  9. public:
  10. Calendar() { //debug
  11. year = 2014;
  12. days = 0;
  13. hours = 6;
  14. minutes = 0;
  15. };
  16. Calendar(int year, int days, int hours, int minutes);
  17.  
  18. ~Calendar();
  19.  
  20. int passHour() {
  21. hours++;
  22. timeUnitPassed();
  23. return getHours();
  24. }
  25.  
  26. void timeUnitPassed() { //Checks if Year or Day has passed;
  27. if ((minutes / 60) == 1) {
  28. hours++;
  29. minutes = 0;
  30. }
  31. if ((hours / 21) == 1) {
  32. days++;
  33. hours = 6;
  34. }
  35. if ((days / 365) == 1) {
  36. year++;
  37. days = 0;
  38. }
  39. }
  40.  
  41. void debugString() {
  42. std::cout << std::to_string(year) + " years " +
  43. std::to_string(days) + " days " +
  44. std::to_string(hours) + " hours" +
  45. std::to_string(minutes) + " minutes\n";
  46. }
  47.  
  48. time_t getDate() {
  49. return ((time_t)year - 1970) * 31557600 + //seconds in a year
  50. (time_t)days * 86400 + //seconds in a day
  51. (time_t)hours * 3600 + //seconds in an hour
  52. (time_t)minutes * 60; //seconds in a minute
  53. }
  54.  
  55. std::string dateToString(time_t seconds) {
  56. char buffer[32];
  57. struct tm * timeinfo; //Time structure
  58.  
  59. timeinfo = localtime(&seconds);
  60. strftime(buffer,32, "%a %d/%b/%G %R", timeinfo); //formats the time based no parameters
  61. return buffer;
  62. }
  63.  
  64. std::string dateToString(int yr, int dy, int hr, int mt) {
  65. return dateToString(
  66. ((time_t)yr - 1970) * 31557600 + //seconds in a year
  67. (time_t)dy * 86400 + //seconds in a day
  68. (time_t)hr * 3600 + //seconds in an hour
  69. (time_t)mt * 60);
  70. }
  71.  
  72. std::string toString() {
  73. return dateToString(year, days, hours, minutes);
  74. }
  75.  
  76. int getYear() {
  77. return year;
  78. }
  79.  
  80. int getHours() {
  81. return hours;
  82. }
  83.  
  84. int getDays() {
  85. return days;
  86. }
  87.  
  88. int getMinutes() {
  89. return minutes;
  90. }
  91.  
  92. private:
  93. int year;
  94. int days;
  95. int hours;
  96. int minutes;
  97. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement