-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @file FingerprintTIME.cpp | ||
* Time and Date functions. | ||
* @author Conlan Wesson | ||
*/ | ||
|
||
#include "FingerprintTIME.h" | ||
#include <chrono> | ||
|
||
namespace Funge { | ||
|
||
FingerprintTIME::FingerprintTIME(FungeRunner& r) : | ||
Fingerprint(r, {'D', 'F', 'G', 'H', 'L', 'M', 'O', 'S', 'W', 'Y'}), | ||
gmt(false) | ||
{} | ||
|
||
FungeError FingerprintTIME::execute(inst_t cmd){ | ||
const std::tm* t = getTime(); | ||
if(t == nullptr){ | ||
return ERROR_UNSPEC; | ||
} | ||
switch(cmd){ | ||
case 'D': | ||
stack.top().push(t->tm_mday); | ||
break; | ||
case 'F': | ||
stack.top().push(t->tm_yday); | ||
break; | ||
case 'G': | ||
gmt = true; | ||
break; | ||
case 'H': | ||
stack.top().push(t->tm_hour); | ||
break; | ||
case 'L': | ||
gmt = false; | ||
break; | ||
case 'M': | ||
stack.top().push(t->tm_min); | ||
break; | ||
case 'O': | ||
stack.top().push(t->tm_mon+1); | ||
break; | ||
case 'S': | ||
stack.top().push(t->tm_sec); | ||
break; | ||
case 'W': | ||
stack.top().push(t->tm_wday+1); | ||
break; | ||
case 'Y': | ||
stack.top().push(t->tm_year+1900); | ||
break; | ||
default: | ||
return ERROR_UNIMP; | ||
} | ||
return ERROR_NONE; | ||
} | ||
|
||
const std::tm* FingerprintTIME::getTime(){ | ||
std::time_t t = std::time(nullptr); | ||
if(gmt){ | ||
return std::gmtime(&t); | ||
}else{ | ||
return std::localtime(&t); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @file FingerprintTIME.h | ||
* Time and Date functions. | ||
* @author Conlan Wesson | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Fingerprint.h" | ||
|
||
namespace Funge { | ||
|
||
class FingerprintTIME : public Fingerprint { | ||
public: | ||
explicit FingerprintTIME(FungeRunner& r); | ||
virtual ~FingerprintTIME() = default; | ||
|
||
virtual FungeError execute(inst_t cmd) override; | ||
|
||
private: | ||
bool gmt; | ||
|
||
const std::tm* getTime(); | ||
}; | ||
|
||
} |