Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdint.h>
- using namespace std;
- char compileDate[16] = __DATE__;
- uint16_t const monPattern[12] = {
- //ascii added together
- 281, // J+a+n = 74+97+110
- 269, // F+e+b = 70+101+98
- 288, // M+a+r = 77+97+114
- 291, // A+p+r = 65+112+114
- 295, // M+a+y = 77+97+121
- 301, // J+u+n = 74+117+110
- 299, // J+u+l = 74+117+108
- 285, // A+u+g = 65+117+103
- 296, // S+e+p = 83+101+112
- 294, // O+c+t = 79+99+116
- 307, // N+o+v = 78+111+118
- 268, // D+e+c = 68+101+99
- };
- //name of months
- const char* months[12] {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
- //get compile month in integers
- int decideMonth(){
- //get monPattern by adding ascii
- int add = 0;
- for(int i=0; i<3;i++){
- add += compileDate[i];
- }
- //what month?
- int mon = 0;
- for(int j=0; j<12; j++){
- if(add==monPattern[j]){
- mon = j+1;
- }
- }
- return mon;
- }
- int month = decideMonth();
- //get compile date in integers
- int decideDate(){
- //get date, converting from ascii to decimal
- int dt=0;
- for (int i=4; i<6; i++){
- if (compileDate[i] != ' '){
- dt = dt*10 + (compileDate[i]-48);
- }
- }
- return dt;
- }
- int date = decideDate();
- //get compile year in integers
- int decideYear(){
- //get year, converting from ascii to decimal
- int yr = 0;
- for (int i=7; i<11; i++){
- yr = yr*10 + (compileDate[i]-48);
- }
- return yr;
- }
- int year = decideYear();
- // number of days in a month
- int get_maxDays(int mon){
- //30 day months
- if (mon==4 || mon==6 || mon==9 || mon==11){
- return 30;
- }
- //special case on Feb
- else if (mon==2){
- if (year%4==0){
- return 29;
- }
- else {
- return 28;
- }
- }
- //31 day months
- else {
- return 31;
- }
- }
- int maxDays = get_maxDays(month);
- const int maxMonth = 12;
- //next month
- void checkMonth(){
- if (date > maxDays){
- date -= maxDays; //1st new month
- month++; //new month
- maxDays = get_maxDays(month); //new month's maxDays
- }
- }
- //next year
- void checkYear(){
- if (month > maxMonth){
- month -= maxMonth; //Jan new year
- year++; //new year
- }
- }
- //when hit 00:00 next day, date++
- //checkMonth() and checkYear() every date++
- //today (idk how to do this)
- string today(){
- return string(months[month-1]) + " " + to_string(date) + " " + to_string(year);
- }
- int main(){
- cout << compileDate << endl;
- cout << months[month-1] << ' ' << date << ' ' << year << endl; //i want the today function to output this thing
- cout << today() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement