diff --git a/core/tags/track.cpp b/core/tags/track.cpp index 1f57804f..f5f471b1 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -25,6 +25,9 @@ Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library, _album(album), _artist(artist), _genre(genre), _library(library), _count(0), _length(length), _track(track), _path(filepath) { + _date.d_day = 0; + _date.d_month = 0; + _date.d_year = 0; filter :: add(this->name(), index()); filter :: add(_artist->name(), index()); filter :: add(_album->name(), index()); @@ -62,9 +65,9 @@ const std::string Track :: date() const std::string res = "Never"; if (_count > 0) { - tm.tm_mday = _date.day; - tm.tm_mon = _date.month - 1; - tm.tm_year = _date.year - 1900; + tm.tm_mday = _date.d_day; + tm.tm_mon = _date.d_month - 1; + tm.tm_year = _date.d_year - 1900; strftime(buffer, 20, "%Ex", &tm); res = buffer; } @@ -98,20 +101,20 @@ void Track :: played() struct tm *now = localtime(&rawtime); _count++; - _date.day = now->tm_mday; - _date.month = now->tm_mon + 1; - _date.year = now->tm_year + 1900; + _date.d_day = now->tm_mday; + _date.d_month = now->tm_mon + 1; + _date.d_year = now->tm_year + 1900; tags :: commit_track_db(); } int Track :: compare_date(const Track *rhs) { - int ret = _date.year - rhs->_date.year; + int ret = _date.d_year - rhs->_date.d_year; if (ret == 0) { - ret = _date.month - rhs->_date.month; + ret = _date.d_month - rhs->_date.d_month; if (ret == 0) - ret = _date.day - rhs->_date.day; + ret = _date.d_day - rhs->_date.d_day; } return ret; } @@ -122,8 +125,8 @@ void Track :: read(file &file) gchar *path; file_readf(&file, "%u %u %u %u %u %u %u %u %u %u", &library_id, - &artist_id, &album_id, &genre_id, &_track, &_date.year, - &_date.month, &_date.day, &_count, &_length); + &artist_id, &album_id, &genre_id, &_track, &_date.d_year, + &_date.d_month, &_date.d_day, &_count, &_length); GenericTag :: read(file); path = file_readl(&file); @@ -145,7 +148,7 @@ void Track :: write(file &file) { file_writef(&file, "%u %u %u %u %u %u %u %u %u %u ", _library->index(), _artist->index(), _album->index(), _genre->index(), _track, - _date.year, _date.month, _date.day, _count, _length); + _date.d_year, _date.d_month, _date.d_day, _count, _length); GenericTag :: write(file); file_writef(&file, "\n%s\n", _path.c_str()); } diff --git a/include/core/date.h b/include/core/date.h new file mode 100644 index 00000000..d5009b02 --- /dev/null +++ b/include/core/date.h @@ -0,0 +1,13 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#ifndef OCARINA_CORE_DATE_H +#define OCARINA_CORE_DATE_H + +struct date { + unsigned int d_year; + unsigned int d_month; + unsigned int d_day; +}; + +#endif /* OCARINA_CORE_DATE_H */ diff --git a/include/core/tags/track.h b/include/core/tags/track.h index 821dbdda..29e04dc4 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -4,6 +4,9 @@ #ifndef OCARINA_CORE_TAGS_TRACK_H #define OCARINA_CORE_TAGS_TRACK_H +extern "C" { +#include +} #include #include #include @@ -11,15 +14,6 @@ #include -/** Structure used to represent dates. */ -struct date { - unsigned int day; /**< Day of the month (1 - 31). */ - unsigned int month; /**< Month of the year (1 - 12). */ - unsigned int year; /**< Number of years, Commen Era. */ - date() : day(0), month(0), year(0) {}; -}; - - /** * The Track tag is used to store information about tracks that * have been added to the tag database. diff --git a/tests/core/.gitignore b/tests/core/.gitignore index 0b6e3836..42a64a8f 100644 --- a/tests/core/.gitignore +++ b/tests/core/.gitignore @@ -1,6 +1,7 @@ version string file +date database index filter diff --git a/tests/core/Sconscript b/tests/core/Sconscript index df72254b..3556bbed 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -17,6 +17,7 @@ res = [ CoreTest("version", "version.c") ] res += [ CoreTest("string", "string.c") ] res += [ CoreTest("random", "random.c") ] res += [ CoreTest("file", "file.c") ] +res += [ CoreTest("date", "date.c") ] res += [ CoreTest("database", "database.cpp") ] res += [ CoreTest("index", "index.cpp") ] res += [ CoreTest("filter", "filter.cpp") ] diff --git a/tests/core/date.c b/tests/core/date.c new file mode 100644 index 00000000..ab77e431 --- /dev/null +++ b/tests/core/date.c @@ -0,0 +1,22 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#include +#include + +void test_date() +{ + struct date date = { + .d_year = 0, + .d_month = 0, + .d_day = 0, + }; + + test_equal(date.d_year, 0); + test_equal(date.d_month, 0); + test_equal(date.d_day, 0); +} + +DECLARE_UNIT_TESTS( + UNIT_TEST("Date", test_date), +);