core/date: Add new file for date structure code
Moving this out of the track class should help to simplify the code. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
7865557fd5
commit
d230396cb2
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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 */
|
|
@ -4,6 +4,9 @@
|
|||
#ifndef OCARINA_CORE_TAGS_TRACK_H
|
||||
#define OCARINA_CORE_TAGS_TRACK_H
|
||||
|
||||
extern "C" {
|
||||
#include <core/date.h>
|
||||
}
|
||||
#include <core/tags/generic.h>
|
||||
#include <core/tags/artist.h>
|
||||
#include <core/tags/album.h>
|
||||
|
@ -11,15 +14,6 @@
|
|||
#include <core/tags/library.h>
|
||||
|
||||
|
||||
/** 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.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
version
|
||||
string
|
||||
file
|
||||
date
|
||||
database
|
||||
index
|
||||
filter
|
||||
|
|
|
@ -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") ]
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/date.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
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),
|
||||
);
|
Loading…
Reference in New Issue