admin
2025-07-17 6cd92a169cbc0db35042f243a09d976fd3e1445c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <wx\string.h>
using namespace std;
/// <summary>
/// ·ÖʱÊý¾Ý°ïÖúÀà
/// </summary>
class TickDataUtil {
public :
    /// <summary>
    /// ½«Ê±¼äתΪS£¬×÷ΪxµÄºá×ø±ê
    /// </summary>
    /// <param name="time_str"></param>
    /// <param name="xStartTimeAsSeconds"></param>
    /// <returns></returns>
    static int timeStrToSecondsAsAxisX(wxString time_str,int xStartTimeAsSeconds) {
        int seconds = timeStrToSeconds(time_str);
        if (seconds > 41400&& xStartTimeAsSeconds<= 41400) { //´óÓÚ11:30
            seconds -= 5400;
        }
        return seconds - xStartTimeAsSeconds;
    }
 
    /// <summary>
    /// timeStrToSecondsAsAxisXµÄÄæ±ä»»
    /// </summary>
    /// <param name="x"></param>
    /// <param name="xStartTimeAsSeconds"></param>
    /// <returns></returns>
    static wxString axisXSecondsToTimeStr(int x, int xStartTimeAsSeconds,bool with_s = TRUE) {
        int seconds = x + xStartTimeAsSeconds;
        if (seconds > 41400&& xStartTimeAsSeconds <= 41400) {
            seconds += 5400;
        }
        return secondToTimeStr(seconds, with_s);
    }
 
 
    static int tradTimeSub(wxString time_str1, wxString time_str2) {
        return timeStrToSecondsAsAxisX(time_str1, 0) - timeStrToSecondsAsAxisX(time_str2, 0);
    }
 
    /// <summary>
    /// ³É½»Ê±¼ä¼ÓÃë
    /// </summary>
    /// <param name="time_str"></param>
    /// <param name="add_seconds"></param>
    /// <returns></returns>
    static wxString tradTimeAdd(wxString time_str, int add_seconds) {
        int seconds = timeStrToSeconds(time_str);
        if (seconds < 41400 && (seconds + add_seconds > 41400)) {
        
             seconds += add_seconds + 5400;
        }
        else {
            seconds += add_seconds;
        }
 
        return secondToTimeStr(seconds, true);
    }
 
    /// <summary>
    /// Ê±¼äתΪs
    /// </summary>
    /// <param name="time_str"></param>
    /// <returns></returns>
    static int timeStrToSeconds(wxString time_str) {
        std::string time_s = time_str.ToStdString();
        int h = stoi(time_s.substr(0, 2).c_str());
        int m = stoi(time_s.substr(3, 2));
        int s = stoi(time_s.substr(6, 2));
        int seconds = h * 3600 + m * 60 + s;
        return seconds;
    }
 
    static wxString secondToTimeStr(int seconds,bool with_s = FALSE) {
        int hour = seconds / 3600;
        int m = seconds % 3600 / 60;
        int s = seconds % 60;
        wxString timeStr = "";
        if (hour < 10)
            timeStr.Append("0");
        timeStr.Append(to_string(hour)).Append(":");
        if (m < 10)
            timeStr.Append("0");
        timeStr.Append(to_string(m));
        if (with_s) {
            timeStr.Append(":");
            if (s < 10)
                timeStr.Append("0");
            timeStr.Append(to_string(s));
        }
        return timeStr;
    }
};