Fix: DateUtil.getDate bug

This commit is contained in:
2018-05-30 09:13:45 +09:00
parent f1cab7de3f
commit cec653abb7
8 changed files with 23 additions and 34 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
class DateUtil { class DateUtil {
static getYYYYMMDD(date) { static getYYYYMMDD(date) {
return date.toISOString().slice(0,10); // return date.toISOString().slice(0,10);
return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
} }
static getHHMMSS(date) { static getHHMMSS(date) {
+2 -2
View File
@@ -13,11 +13,11 @@ class Game {
let scoreBoard = new ScoreBoard(); let scoreBoard = new ScoreBoard();
scoreManager.addOnChangeScoreListener( score => { scoreManager.addOnChangeScoreListener( score => {
sessionStorageManager.score = score; sessionStorageManager.record = score;
scoreBoard.printScore(NumberUtil.numberWithCommas(score)); scoreBoard.printScore(NumberUtil.numberWithCommas(score));
}); });
scoreManager.addOnChangeHighScoreListener( highScore => { scoreManager.addOnChangeHighScoreListener( highScore => {
sessionStorageManager.highScore = highScore; sessionStorageManager.bestRecord = highScore;
screenBottom.printBottomLeftText("최고 기록 : " + NumberUtil.numberWithCommas(highScore)); screenBottom.printBottomLeftText("최고 기록 : " + NumberUtil.numberWithCommas(highScore));
}); });
+1 -9
View File
@@ -23,17 +23,9 @@ class HistoryBoard {
return; return;
} }
let maxIndex = historyRecordManager.count - 1;
if(maxIndex > 6)
maxIndex = 6;
for(let i = 0; i < historyRecordManager.count; i++) { for(let i = 0; i < historyRecordManager.count; i++) {
if(i > 6) let data = historyRecordManager.getAt(i);
break;
let data = historyRecordManager.getAt(maxIndex);
this.printRecord(i, data.date, data.bestRecord); this.printRecord(i, data.date, data.bestRecord);
maxIndex--;
} }
} }
); );
+2 -2
View File
@@ -28,9 +28,9 @@ function get_history_record($app_id, $user_id, $date) {
SELECT DATE(BR.RecordDateTime) AS Date, MAX(BR.BestRecord) AS HighScore, AA.AppName AS AppName SELECT DATE(BR.RecordDateTime) AS Date, MAX(BR.BestRecord) AS HighScore, AA.AppName AS AppName
FROM moty_best_record BR FROM moty_best_record BR
INNER JOIN moty_app AS AA INNER JOIN moty_app AS AA
ON BR.UserID = ? AND DATE(BR.RecordDateTime) < DATE(?) AND BR.AppID = ? AND BR.AppID = AA.AppID ON BR.UserID = ? AND DATE(BR.RecordDateTime) < ? AND BR.AppID = ? AND BR.AppID = AA.AppID
GROUP BY DATE(BR.RecordDateTime) GROUP BY DATE(BR.RecordDateTime)
ORDER BY BR.RecordDateTime ASC ORDER BY BR.RecordDateTime DESC
LIMIT 7 LIMIT 7
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
+3 -3
View File
@@ -5,14 +5,14 @@ include "./../lib/send_error_code.php";
$app_id = $_POST["AppID"]; $app_id = $_POST["AppID"];
$date = $_POST["Date"]; $date = $_POST["Date"];
// $time = $_POST["Time"]; $time = $_POST["Time"];
include "./../setup/connect_db.php"; include "./../setup/connect_db.php";
$replyJSON = get_ranking_record_day($date, $app_id); $replyJSON = get_ranking_record_day($date, $app_id);
if($replyJSON.length === 0) { if($replyJSON.length === 0) {
send_error_message($replyJSON, "히스토리 기록 없음"); send_error_message($replyJSON, "오늘의 랭킹 기록 없음");
$db_conn->close(); $db_conn->close();
exit; exit;
} }
@@ -27,7 +27,7 @@ function get_ranking_record_day($date, $app_id) {
$query = " $query = "
SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore
FROM moty_best_record BR, moty_user U FROM moty_best_record BR, moty_user U
WHERE BR.userID = U.userID AND DATE(BR.RecordDateTime) = DATE(?) AND AppID = ? WHERE BR.userID = U.userID AND DATE(BR.RecordDateTime) = ? AND AppID = ?
GROUP BY BR.userID GROUP BY BR.userID
ORDER BY max(BR.BestRecord) DESC; ORDER BY max(BR.BestRecord) DESC;
"; ";
@@ -12,7 +12,7 @@ include "./../setup/connect_db.php";
$replyJSON = get_ranking_record_hour($date, $time, $app_id); $replyJSON = get_ranking_record_hour($date, $time, $app_id);
if($replyJSON.length === 0) { if($replyJSON.length === 0) {
send_error_message($replyJSON, "히스토리 기록 없음"); send_error_message($replyJSON, "수업시간 랭킹 기록 없음");
$db_conn->close(); $db_conn->close();
exit; exit;
} }
@@ -20,21 +20,19 @@ if($replyJSON.length === 0) {
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close(); $db_conn->close();
function get_ranking_record_hour($date, $time, $app_id) { function get_ranking_record_hour($date, $time, $app_id) {
global $db_conn; global $db_conn;
$query = " $query = "
SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore SELECT BR.userID As UserID, U.Name AS Name, MAX(BR.BestRecord) AS HighScore
FROM moty_best_record BR, moty_user U FROM moty_best_record BR, moty_user U
WHERE BR.userID = U.userID AND DATE(BR.RecordDateTime) = DATE(?) AND HOUR(BR.RecordDateTime) = HOUR(?) AND AppID = ? WHERE BR.userID = U.userID AND DATE(BR.RecordDateTime) = ? AND HOUR(BR.RecordDateTime) = HOUR(?) AND AppID = ?
GROUP BY BR.userID GROUP BY BR.userID
ORDER BY max(BR.BestRecord) DESC; ORDER BY max(BR.BestRecord) DESC;
"; ";
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('ssi', $date, $time, $app_id); $stmt->bind_param('ssi', $date, $time, $app_id);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($userID, $name, $high_score); $stmt->bind_result($userID, $name, $high_score);
$ranking_record_array = array(); $ranking_record_array = array();
@@ -12,7 +12,7 @@ include "./../setup/connect_db.php";
$replyJSON = get_ranking_record_month($date, $time, $app_id); $replyJSON = get_ranking_record_month($date, $time, $app_id);
if($replyJSON.length === 0) { if($replyJSON.length === 0) {
send_error_message($replyJSON, "히스토리 기록 없음"); send_error_message($replyJSON, "이달의 랭킹 기록 없음");
$db_conn->close(); $db_conn->close();
exit; exit;
} }
@@ -34,17 +34,16 @@ function get_ranking_record_month($date, $time, $app_id) {
$stmt = $db_conn->prepare($query); $stmt = $db_conn->prepare($query);
$stmt->bind_param('si', $date, $app_id); $stmt->bind_param('si', $date, $app_id);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($userID, $name, $high_score); $stmt->bind_result($userID, $name, $high_score);
$score_record_array = array(); $ranking_record_array = array();
while($stmt->fetch()) { while($stmt->fetch()) {
$score_record['UserID'] = $userID; $ranking_record['UserID'] = $userID;
$score_record['Name'] = $name; $ranking_record['Name'] = $name;
$score_record['HighScore'] = $high_score; $ranking_record['HighScore'] = $high_score;
array_push($score_record_array, $score_record); array_push($ranking_record_array, $ranking_record);
} }
$return_array['rankingMonth'] = $score_record_array; $return_array['rankingMonth'] = $ranking_record_array;
return $return_array; return $return_array;
} }
+4 -5
View File
@@ -36,12 +36,12 @@ QUnit.test( "Player history", function( assert ) {
console.log(historyRecordManager); console.log(historyRecordManager);
assert.equal(historyRecordManager.getAppNameAt(0), "korean_word"); assert.equal(historyRecordManager.getAppNameAt(0), "korean_word");
assert.equal(historyRecordManager.getDateAt(0), "2018-04-18"); assert.equal(historyRecordManager.getDateAt(0), "2018-05-14");
assert.equal(historyRecordManager.getBestRecordAt(0), 51.6102); assert.equal(historyRecordManager.getBestRecordAt(0), 101.78);
assert.equal(historyRecordManager.getAppNameAt(4), "korean_word"); assert.equal(historyRecordManager.getAppNameAt(4), "korean_word");
assert.equal(historyRecordManager.getDateAt(4), "2018-05-14"); assert.equal(historyRecordManager.getDateAt(4), "2018-04-18");
assert.equal(historyRecordManager.getBestRecordAt(4), 101.78); assert.equal(historyRecordManager.getBestRecordAt(4), 51.6102);
done(); done();
} }
@@ -51,7 +51,6 @@ QUnit.test( "Player history", function( assert ) {
QUnit.test( "Player ranking", function( assert ) { QUnit.test( "Player ranking", function( assert ) {
sessionStorageManager.playingAppID = 9; sessionStorageManager.playingAppID = 9;
// sessionStorageManager.playingAppName = "korean_word";
let date = "2018-05-16"; let date = "2018-05-16";
let time = "14:50:00"; let time = "14:50:00";