fixed #2055
This commit is contained in:
parent
50c781da5d
commit
96f4e38e38
|
@ -83,13 +83,22 @@ class Conversion
|
|||
|
||||
public:
|
||||
/**
|
||||
* Convert a boost::ptime to a odbc::Timestamp.
|
||||
* Constants to specify whether we round time values up or down.
|
||||
*/
|
||||
typedef enum { roundDown,
|
||||
roundUp,
|
||||
roundNearest } RoundingType;
|
||||
|
||||
/**
|
||||
* Convert a boost::ptime to a odbc::Timestamp, rounding down.
|
||||
*
|
||||
* @param ptime the boost ptime to convert.
|
||||
* @return an odbc::Timestamp, holding the same time.
|
||||
*/
|
||||
static Ptr<odbc::Timestamp>::Ref
|
||||
ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime) throw ();
|
||||
ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime,
|
||||
RoundingType round = roundDown)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Convert an odbc::Timestamp to a boost::ptime.
|
||||
|
|
|
@ -56,18 +56,26 @@ using namespace LiveSupport::Db;
|
|||
* Convert a boost::ptime to an odbc::Timestamp
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<odbc::Timestamp>::Ref
|
||||
Conversion :: ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime)
|
||||
Conversion :: ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime,
|
||||
RoundingType round)
|
||||
throw ()
|
||||
{
|
||||
gregorian::date date = ptime->date();
|
||||
posix_time::time_duration hours = ptime->time_of_day();
|
||||
posix_time::ptime newPtime = *ptime;
|
||||
if (round == roundUp && newPtime.time_of_day().fractional_seconds() != 0) {
|
||||
newPtime += posix_time::seconds(1);
|
||||
} else if (round == roundNearest) {
|
||||
newPtime += posix_time::microseconds(500000);
|
||||
}
|
||||
|
||||
gregorian::date date = newPtime.date();
|
||||
posix_time::time_duration time = newPtime.time_of_day();
|
||||
|
||||
Ptr<odbc::Timestamp>::Ref timestamp(new odbc::Timestamp(date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
hours.hours(),
|
||||
hours.minutes(),
|
||||
hours.seconds()));
|
||||
time.hours(),
|
||||
time.minutes(),
|
||||
time.seconds()));
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
|
|
@ -322,12 +322,12 @@ PostgresqlSchedule :: isTimeframeAvailable(
|
|||
Ptr<Timestamp>::Ref timestamp;
|
||||
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
|
||||
isTimeframaAvailableStmt));
|
||||
timestamp = Conversion::ptimeToTimestamp(from);
|
||||
timestamp = Conversion::ptimeToTimestamp(from, Conversion::roundDown);
|
||||
pstmt->setTimestamp(1, *timestamp);
|
||||
pstmt->setTimestamp(2, *timestamp);
|
||||
pstmt->setTimestamp(5, *timestamp);
|
||||
|
||||
timestamp = Conversion::ptimeToTimestamp(to);
|
||||
timestamp = Conversion::ptimeToTimestamp(to, Conversion::roundUp);
|
||||
pstmt->setTimestamp(3, *timestamp);
|
||||
pstmt->setTimestamp(4, *timestamp);
|
||||
pstmt->setTimestamp(6, *timestamp);
|
||||
|
@ -370,11 +370,13 @@ PostgresqlSchedule :: schedulePlaylist(
|
|||
pstmt->setLong(1, id->getId());
|
||||
pstmt->setLong(2, playlist->getId()->getId());
|
||||
|
||||
timestamp = Conversion::ptimeToTimestamp(playtime);
|
||||
timestamp = Conversion::ptimeToTimestamp(playtime,
|
||||
Conversion::roundNearest);
|
||||
pstmt->setTimestamp(3, *timestamp);
|
||||
|
||||
ends.reset(new ptime((*playtime) + *(playlist->getPlaylength())));
|
||||
timestamp = Conversion::ptimeToTimestamp(ends);
|
||||
timestamp = Conversion::ptimeToTimestamp(ends,
|
||||
Conversion::roundUp);
|
||||
pstmt->setTimestamp(4, *timestamp);
|
||||
|
||||
result = pstmt->executeUpdate() == 1;
|
||||
|
@ -416,10 +418,12 @@ PostgresqlSchedule :: storeScheduleEntry(
|
|||
pstmt->setLong(1, scheduleEntry->getId()->getId());
|
||||
pstmt->setLong(2, scheduleEntry->getPlaylistId()->getId());
|
||||
|
||||
timestamp = Conversion::ptimeToTimestamp(scheduleEntry->getStartTime());
|
||||
timestamp = Conversion::ptimeToTimestamp(scheduleEntry->getStartTime(),
|
||||
Conversion::roundDown);
|
||||
pstmt->setTimestamp(3, *timestamp);
|
||||
|
||||
timestamp = Conversion::ptimeToTimestamp(scheduleEntry->getEndTime());
|
||||
timestamp = Conversion::ptimeToTimestamp(scheduleEntry->getEndTime(),
|
||||
Conversion::roundUp);
|
||||
pstmt->setTimestamp(4, *timestamp);
|
||||
|
||||
result = pstmt->executeUpdate() == 1;
|
||||
|
@ -456,9 +460,11 @@ PostgresqlSchedule :: getScheduleEntries(
|
|||
Ptr<Timestamp>::Ref timestamp;
|
||||
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
|
||||
getScheduleEntriesStmt));
|
||||
timestamp = Conversion::ptimeToTimestamp(fromTime);
|
||||
timestamp = Conversion::ptimeToTimestamp(fromTime,
|
||||
Conversion::roundDown);
|
||||
pstmt->setTimestamp(1, *timestamp);
|
||||
timestamp = Conversion::ptimeToTimestamp(toTime);
|
||||
timestamp = Conversion::ptimeToTimestamp(toTime,
|
||||
Conversion::roundUp);
|
||||
pstmt->setTimestamp(2, *timestamp);
|
||||
|
||||
Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
|
||||
|
@ -565,7 +571,7 @@ PostgresqlSchedule :: getCurrentlyPlaying(void) throw ()
|
|||
Ptr<Timestamp>::Ref timestamp;
|
||||
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
|
||||
getCurrentlyPlayingStmt));
|
||||
timestamp = Conversion::ptimeToTimestamp(now);
|
||||
timestamp = Conversion::ptimeToTimestamp(now, Conversion::roundNearest);
|
||||
pstmt->setTimestamp(1, *timestamp);
|
||||
pstmt->setTimestamp(2, *timestamp);
|
||||
|
||||
|
@ -611,7 +617,8 @@ PostgresqlSchedule :: getNextEntry(Ptr<ptime>::Ref fromTime)
|
|||
Ptr<Timestamp>::Ref timestamp;
|
||||
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
|
||||
getNextEntryStmt));
|
||||
timestamp = Conversion::ptimeToTimestamp(fromTime);
|
||||
timestamp = Conversion::ptimeToTimestamp(fromTime,
|
||||
Conversion::roundDown);
|
||||
pstmt->setTimestamp(1, *timestamp);
|
||||
|
||||
Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
|
||||
|
@ -781,10 +788,12 @@ PostgresqlSchedule :: reschedule(Ptr<UniqueId>::Ref entryId,
|
|||
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
|
||||
reschedulePlaylistStmt));
|
||||
|
||||
timestamp = Conversion::ptimeToTimestamp(playtime);
|
||||
timestamp = Conversion::ptimeToTimestamp(playtime,
|
||||
Conversion::roundNearest);
|
||||
pstmt->setTimestamp(1, *timestamp);
|
||||
|
||||
timestamp = Conversion::ptimeToTimestamp(ends);
|
||||
timestamp = Conversion::ptimeToTimestamp(ends,
|
||||
Conversion::roundUp);
|
||||
pstmt->setTimestamp(2, *timestamp);
|
||||
|
||||
pstmt->setLong(3, entryId->getId());
|
||||
|
|
Loading…
Reference in New Issue