Skip to content

Commit d7e086c

Browse files
committed
store and sort dates by timestamp not string (#38)
1 parent a3ae942 commit d7e086c

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

source/create_dialog_derived.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void CreateProjectDialogD::OnCreate(wxCommandEvent& event){
122122
);
123123
#endif
124124
//TODO: return this command to what summoned this dialog
125-
project p = {projName,e.name,"",filesystem::path(projPath) / filesystem::path(projName)};
125+
project p = {projName,e.name,0,filesystem::path(projPath) / filesystem::path(projName)};
126126
this->callback(command,p);
127127

128128
//close and dispose self

source/globals.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ ParsedVersion parseVersion(const std::string_view version) {
2323
return {};
2424
}
2525

26+
27+
std::string project::modifyDateString() const {
28+
long reducedTime = modifiedDate; //NOTE: 32-bit time precision loss
29+
return ctime(&reducedTime);
30+
}
31+
2632
void launch_process(const std::string& command, int flags) {
2733
#if defined __APPLE__ || defined __linux__
2834
//the '&' runs the command nonblocking, and >/dev/null 2>&1 destroys output

source/globals.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ struct editor {
133133
struct project {
134134
std::string name;
135135
std::string version;
136-
std::string modifiedDate;
136+
int64_t modifiedDate;
137137
std::filesystem::path path;
138138
bool operator==(const project& other) const {
139139
return this->path == other.path;
140140
}
141+
std::string modifyDateString() const;
141142
};
142143

143144
struct ParsedVersion {

source/interface_derived.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,11 @@ project MainFrameDerived::LoadProject(const std::filesystem::path &p_as_fs){
509509
}
510510

511511
//get the modification date
512-
string modifyDate;
512+
int64_t modifyDate;
513513
struct stat fileInfo {};
514514
if (filesystem::exists(p_as_fs)) {
515515
if (stat(p_as_fs.string().c_str(), &fileInfo) == 0) {
516-
modifyDate = ctime(&fileInfo.st_mtime);
516+
modifyDate = fileInfo.st_mtime;
517517
}
518518
}
519519

@@ -582,7 +582,7 @@ void MainFrameDerived::AddProject(const project& p, const std::string& filter, b
582582
projectsList->SetItemData(itemIndex, projectIndex);
583583

584584
projectsList->SetItem(itemIndex, 1, p.version);
585-
projectsList->SetItem(itemIndex, 2, p.modifiedDate);
585+
projectsList->SetItem(itemIndex, 2, p.modifyDateString());
586586
projectsList->SetItem(itemIndex, 3, p.path.string());
587587

588588
//resize columns
@@ -760,9 +760,7 @@ int wxCALLBACK MainFrameDerived::CompareItems(wxIntPtr item1, wxIntPtr item2, wx
760760
break;
761761
}
762762
case 2: // Last Modified
763-
// Compare dates - note: string comparison may not work correctly for all date formats
764-
// For dates, default to newest first (reverse the comparison)
765-
result = p2.modifiedDate.compare(p1.modifiedDate);
763+
result = int(std::clamp<int64_t>(p2.modifiedDate - p1.modifiedDate,-10,10));
766764
break;
767765
case 3: // Path
768766
result = p1.path.string().compare(p2.path.string());

0 commit comments

Comments
 (0)