Add command: skids now
This commit is contained in:
parent
fd73f51c91
commit
3523cf677e
|
@ -1,29 +1,25 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/bin/skidjular",
|
||||
"args": [ "init" ],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}/build/bin/",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/usr/bin/gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "Build Debug"
|
||||
}
|
||||
]
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit:
|
||||
// https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version" : "0.2.0", "configurations" : [{
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/bin/skidjular",
|
||||
"args": ["skids", "now"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}/build/bin/",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/usr/bin/gdb",
|
||||
"setupCommands": [{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}],
|
||||
"preLaunchTask": "Build Debug"
|
||||
}]
|
||||
}
|
39
src/data.cpp
39
src/data.cpp
|
@ -2,7 +2,7 @@
|
|||
#include "log.h"
|
||||
|
||||
void to_json(json& j, const Date& date) {
|
||||
j = json{{"day", date.day}, {"month", date.day}, {"year", date.year}};
|
||||
j = json{{"day", date.day}, {"month", date.month}, {"year", date.year}};
|
||||
}
|
||||
void from_json(const json& j, Date& date) {
|
||||
j.at("day").get_to(date.day);
|
||||
|
@ -28,19 +28,19 @@ void from_json(const json& j, Project& proj) {
|
|||
j.at("isDone").get_to(proj.isDone);
|
||||
}
|
||||
void to_json(json& j, const Skid& skid) {
|
||||
Project projects;
|
||||
if (skid.projects != nullptr) {
|
||||
projects = *skid.projects;
|
||||
Project project;
|
||||
if (skid.project != nullptr) {
|
||||
project = *skid.project;
|
||||
}
|
||||
j = json{
|
||||
{"projects", projects},
|
||||
{"project", project},
|
||||
{"creationDate", skid.creationDate},
|
||||
{"date", skid.date},
|
||||
};
|
||||
}
|
||||
void from_json(const json& j, Skid& skid) {
|
||||
skid.projects = new Project();
|
||||
j.at("projects").get_to(*skid.projects);
|
||||
skid.project = new Project();
|
||||
j.at("project").get_to(*skid.project);
|
||||
j.at("creationDate").get_to(skid.creationDate);
|
||||
j.at("date").get_to(skid.date);
|
||||
}
|
||||
|
@ -135,31 +135,6 @@ Date get_today() {
|
|||
return res;
|
||||
}
|
||||
|
||||
int get_day_num(Date initial) {
|
||||
auto m = (initial.month + 9) % 12;
|
||||
auto y = initial.year - m / 10;
|
||||
return 365 * y + y / 4 - y / 100 + y / 400 + (m * 306 + 5) / 10 +
|
||||
(initial.day - 1);
|
||||
}
|
||||
|
||||
Date get_day_date(int g) {
|
||||
auto y = (10000 * g + 14780) / 3652425;
|
||||
auto ddd = g - (365 * y + y / 4 - y / 100 + y / 400);
|
||||
if (ddd < 0)
|
||||
y = y - 1;
|
||||
ddd = g - (365 * y + y / 4 - y / 100 + y / 400);
|
||||
auto mi = (100 * ddd + 52) / 3060;
|
||||
auto mm = (mi + 2) % 12 + 1;
|
||||
y = y + (mi + 2) / 12;
|
||||
auto dd = ddd - (mi * 306 + 5) / 10 + 1;
|
||||
|
||||
Date res;
|
||||
res.year = y;
|
||||
res.month = mm;
|
||||
res.day = dd;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool is_empty(std::ifstream& pFile) {
|
||||
return pFile.peek() == std::ifstream::traits_type::eof();
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ struct Project {
|
|||
};
|
||||
|
||||
struct Skid {
|
||||
Project* projects = nullptr;
|
||||
Project* project = nullptr;
|
||||
Date creationDate;
|
||||
Date date;
|
||||
};
|
||||
|
@ -74,7 +74,7 @@ struct DB {
|
|||
std::map<std::string, Project>* projects;
|
||||
std::vector<Skid> skids;
|
||||
Log log;
|
||||
int lastSkidID = 0;
|
||||
int lastSkidID = 1;
|
||||
|
||||
Date creationDate;
|
||||
Date lastAccessTime;
|
||||
|
|
|
@ -15,7 +15,7 @@ void skids_init(skids_args args) {
|
|||
}
|
||||
|
||||
/* Create skids */
|
||||
for (size_t i = 0; i < 7; i++) {
|
||||
for (size_t i = 1; i <= 7; i++) {
|
||||
Skid skid;
|
||||
skid.creationDate = get_today();
|
||||
skid.date = firstDate;
|
||||
|
@ -34,7 +34,7 @@ void skids_init_now(skids_args args) {
|
|||
/* Load all skids */
|
||||
if (is_path_exist(LOC_SKIDID + std::to_string(args.db->lastSkidID))) {
|
||||
/* Load all skids */
|
||||
for (size_t i = 0; i < args.db->lastSkidID; i++) {
|
||||
for (size_t i = 1; i <= args.db->lastSkidID; i++) {
|
||||
Skid skid;
|
||||
loadSkid(skid, i);
|
||||
args.db->skids.push_back(skid);
|
||||
|
@ -57,7 +57,7 @@ void skids_init_now(skids_args args) {
|
|||
|
||||
/* Create skids */
|
||||
auto firstDate = get_today();
|
||||
for (size_t i = 0; i < 7; i++) {
|
||||
for (size_t i = 1; i <= 7; i++) {
|
||||
Skid skid;
|
||||
skid.creationDate = get_today();
|
||||
skid.date = firstDate;
|
||||
|
@ -68,7 +68,38 @@ void skids_init_now(skids_args args) {
|
|||
args.db->lastSkidID = skid_id;
|
||||
writeDB(*args.db, LOC_DB);
|
||||
}
|
||||
void skids_now(skids_args args) {}
|
||||
|
||||
void skids_now(skids_args args) {
|
||||
logEntry("Accessing today's skid, skids_now", EntryType::Access);
|
||||
/* Load all skids */
|
||||
for (size_t i = 1; i <= args.db->lastSkidID; i++) {
|
||||
Skid skid;
|
||||
loadSkid(skid, i);
|
||||
args.db->skids.push_back(skid);
|
||||
}
|
||||
|
||||
/* Get today's skidID */
|
||||
Skid* skid = nullptr;
|
||||
for (size_t i = 0; i < args.db->skids.size(); i++) {
|
||||
if (args.db->skids[i].date == get_today()) {
|
||||
skid = &(args.db->skids[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skid) {
|
||||
std::cout << "Did not find today's skid." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (skid->project->name == "") {
|
||||
std::cout << "Today's project is not set." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::cout << "Project of today is " << skid->project->name << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
void skids_this(skids_args args) {}
|
||||
void skids_set_this(skids_args args) {}
|
||||
void skids_set_this_lazy(skids_args args) {}
|
||||
|
|
Loading…
Reference in New Issue