标题:请教下各位大大:有没有体育项目秒表时间的加减算法?
只看楼主
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用shonken在2022-7-8 15:22:10的发言:

吹版,跟csyx说的差不多,平时应用类似这样
*-- 测试样例
? 秒表('0:10:10.123', '1.123')
? 秒表('0:10:10.123', '+1.123')
? 秒表('10:10.123', 1.123)
? 秒表('1:10:10.123', -1.124)
? 秒表('1:10:10.123', '-11:1.124')     && 0:59:08.999 与你要的结果不同
? 秒表('0:59:08.999', '+11:1.124') == '1:10:10.123

结果看似时点数
试试:
? 秒表('3:00:00', '-4:00:00')
? 秒表('3:00:00', '+21:00:00')
是你想要的结果吗?
2022-07-08 15:53
shonken
Rank: 2
等 级:论坛游民
帖 子:95
专家分:21
注 册:2017-1-15
得分:0 
*-- 测试样例
? 秒表('0:10:10.123', '1.123')=>00:10:11.246

? 秒表('0:10:10.123', '+1.123')=>00:10:11.246

? 秒表('10:10.123', 1.123)=>00:10:11.246

? 秒表('1:10:10.123', -1.124)=>01:10:08.999

? 秒表('1:10:10.123', '-11:1.124') =>00:59:08.999

? 秒表('0:59:08.999', '+11:1.124') =>1:10:10.123

不单单是小时数的增减,天、时、分、秒、毫秒都要加减运算

以下是引用吹水佬在2022-7-8 15:53:12的发言:


结果看似时点数
试试:
? 秒表('3:00:00', '-4:00:00')
? 秒表('3:00:00', '+21:00:00')
是你想要的结果吗?



[此贴子已经被作者于2022-7-8 16:40编辑过]

2022-07-08 16:34
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用shonken在2022-7-8 16:34:06的发言:
不单单是小时数的增减,天、时、分、秒、毫秒都要加减运算

所以,不只是time的问题,是datetime的问题吧?
in/out格式"hh:mm:ss"可能达不到要求
最好将问题要求详细点说说,对日期、时间有什么限制,例举最好能涉及问题所在。


[此贴子已经被作者于2022-7-8 16:55编辑过]

2022-07-08 16:54
a57598587
Rank: 2
等 级:论坛游民
威 望:4
帖 子:29
专家分:29
注 册:2022-1-24
得分:2 
抛砖引玉请大侠指导:
程序代码:
cc10 = ThisForm.Text1.Value && 时:分:秒.微秒 格式
cc10 ="01:01:01.123"

*?OCCURS(":",cc10)
cc11 = REPLICATE ("0:",2-OCCURS(":",cc10))-cc10

?cc11
*ALINES(sj1, cc11, 5, ":", ".")
ALINES(sj1, cc11, 5, ".")
?sj1[1]
?sj1[2]
sj101 = CTOT(sj1[1])-CTOT("0:0:0")
sj102 = INT(val(sj1[2]))

?"秒",sj101,"微秒", sj102

?"================"

cc20 = ThisForm.Text2.Value && 时:分:秒.微秒 格式

cc20 =  "01.223"
*?OCCURS(":",cc10)
cc21 = REPLICATE ("0:",2-OCCURS(":",cc20))-cc20

?cc21
*ALINES(sj1, cc11, 5, ":", ".")
ALINES(sj2, cc21, 5, ".")
?sj2[1]
?sj2[2]
sj201 = CTOT(sj2[1])-CTOT("0:0:0")
sj202 = INT(val(sj2[2]))

?"秒",sj201,"微秒", sj202

?"================增加"&&同理可做减少代码
IF sj102+sj202>=1000
    sj31 =sj101 +sj201+1
    sj32 = sj202+sj102 -1000

ELSE 
    sj31 =sj101 +sj201
    sj32 = sj202+sj102 
ENDIF 
?"成绩:",sj31,"秒",sj32,"微秒"

sj41=CTOT("0:0:0")+sj31
?HOUR(sj41)
?MINUTE(sj41)
?SEC(sj41)
?sj32

?"成绩显示:",STR(HOUR(sj41),2,0)+":"+STR(MINUTE(sj41),2,0)+":"+STR(SEC(sj41),2,0)+"."+STR(sj32,3,0)
2022-07-08 21:50
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:0 
楼主的问题,处理后的结果,可以大于24小时,但不能小于0
2022-07-09 01:25
a57598587
Rank: 2
等 级:论坛游民
威 望:4
帖 子:29
专家分:29
注 册:2022-1-24
得分:0 
回复 25楼 mywisdom88
这个是体育测试,应该不会大于24小时吧? 第二步的加或减应该是对成绩的校正
2022-07-09 06:27
shonken
Rank: 2
等 级:论坛游民
帖 子:95
专家分:21
注 册:2017-1-15
得分:0 
mywisdom88版主理解正确,体育项目一般都是以增加时间为主,一些长时间的项目会跨天,如我上面说的100KM越野,清早5点出发,好多人完赛都要隔天的中午了,跨度十几小时至三十小时不等。也有些体育项目会轻微的减少时间作为奖励,一般是减少分、秒、毫秒。

以下是引用mywisdom88在2022-7-9 01:25:06的发言:

楼主的问题,处理后的结果,可以大于24小时,但不能小于0

2022-07-09 10:06
shonken
Rank: 2
等 级:论坛游民
帖 子:95
专家分:21
注 册:2017-1-15
得分:0 
谢谢你的思路

以下是引用a57598587在2022-7-8 21:50:01的发言:

抛砖引玉请大侠指导:
cc10 = ThisForm.Text1.Value && 时:分:秒.微秒 格式
cc10 ="01:01:01.123"

*?OCCURS(":",cc10)
cc11 = REPLICATE ("0:",2-OCCURS(":",cc10))-cc10

?cc11
*ALINES(sj1, cc11, 5, ":", ".")
ALINES(sj1, cc11, 5, ".")
?sj1[1]
?sj1[2]
sj101 = CTOT(sj1[1])-CTOT("0:0:0")
sj102 = INT(val(sj1[2]))

?"秒",sj101,"微秒", sj102

?"================"

cc20 = ThisForm.Text2.Value && 时:分:秒.微秒 格式

cc20 =  "01.223"
*?OCCURS(":",cc10)
cc21 = REPLICATE ("0:",2-OCCURS(":",cc20))-cc20

?cc21
*ALINES(sj1, cc11, 5, ":", ".")
ALINES(sj2, cc21, 5, ".")
?sj2[1]
?sj2[2]
sj201 = CTOT(sj2[1])-CTOT("0:0:0")
sj202 = INT(val(sj2[2]))

?"秒",sj201,"微秒", sj202

?"================增加"&&同理可做减少代码
IF sj102+sj202>=1000
    sj31 =sj101 +sj201+1
    sj32 = sj202+sj102 -1000

ELSE
    sj31 =sj101 +sj201
    sj32 = sj202+sj102
ENDIF
?"成绩:",sj31,"秒",sj32,"微秒"

sj41=CTOT("0:0:0")+sj31
?HOUR(sj41)
?MINUTE(sj41)
?SEC(sj41)
?sj32

?"成绩显示:",STR(HOUR(sj41),2,0)+":"+STR(MINUTE(sj41),2,0)+":"+STR(SEC(sj41),2,0)+"."+STR(sj32,3,0)

2022-07-09 10:14
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
程序代码:
DECLARE long time      IN msvcrt as apiTime
DECLARE long localtime IN msvcrt as apiLocaltime long@
nt = apiTime()
? addDatetime(nt, 0)                    && 当前日期时间
? addDatetime(nt, 3600*24+3600+60+1)    && 加1日1小时1分1秒
? addDatetime(nt, -3600*24-3600-60-1)   && 减1日1小时1分1秒
CLEAR ALL
RETURN

FUNCTION addDatetime(nt, num)
    nt = nt + num
    ptm = apiLocaltime(@nt)
    RETURN PADL(CTOBIN(SYS(2600,ptm+20,4),"4RS")+1900, 4, "0")+"-"+;
           PADL(CTOBIN(SYS(2600,ptm+16,4),"4RS")+1,    2, "0")+"-"+;
           PADL(CTOBIN(SYS(2600,ptm+12,4),"4RS"),      2, "0")+" "+;
           PADL(CTOBIN(SYS(2600,ptm+8, 4),"4RS"),      2, "0")+":"+;
           PADL(CTOBIN(SYS(2600,ptm+4, 4),"4RS"),      2, "0")+":"+;
           PADL(CTOBIN(SYS(2600,ptm,   4),"4RS"),      2, "0")
ENDFUNC
2022-07-09 11:10
shonken
Rank: 2
等 级:论坛游民
帖 子:95
专家分:21
注 册:2017-1-15
得分:0 
交功课,主要借鉴csyx的代码为主,加上些实际应用,没用类的方式

程序代码:
Clear
? x_秒表加减('0:10:10.123', '1.123')
? x_秒表加减('0:10:10.123', '+1.123')
? x_秒表加减('10:10.123', 1.123)
? x_秒表加减('1:10:10.123', -1.124)
? x_秒表加减('1:10:10.123', '-11:1.124')
? x_秒表加减('2022-07-09T23:59:08.999', '+11:1.124')
? x_秒表加减('2000-01-01T00:10:11.123','1.123')
? x_秒表加减(x_秒表加减(x_秒表加减('0', 1.123), '+11:1.124'), '-1.124')
Function x_秒表加减
    Lparameters lcValue1,lcValue2
    lcValue2 = Iif(Vartype(lcValue2) == 'N', Transform(lcValue2), Alltrim(lcValue2))
    Local ArTime1,ArTime2,LnSs, LnTt, LnMs, LnY, LnM, LnD
    Dimension ArTime1[4],ArTime2[4]
    ArTime1=x_formatTime(lcValue1)&&格式化输入数据,并装入数组
    ArTime2=x_formatTime(lcValue2)
    If Vartype(ArTime1)="L" Or Vartype(ArTime2)="L"
        Return .F.
    Endif
    LnY = Year(Date())
    LnM = Month(Date())
    LnD = Day(Date())
    LnSs = ArTime2[1] * 3600 + ArTime2[2] * 60 + ArTime2[3]
    If Left(lcValue2, 1) == '-'
        LnTt = Datetime(LnY,LnM,LnD, ArTime1[1], ArTime1[2], ArTime1[3]) - LnSs
        LnMs = ArTime1[4] - ArTime2[4]
        If LnMs < 0
            LnTt = LnTt - 1
            LnMs = LnMs + 1000
        Endif
    Else
        LnTt = Datetime(LnY,LnM,LnD, ArTime1[1], ArTime1[2], ArTime1[3]) + LnSs
        LnMs = ArTime1[4] + ArTime2[4]
        If LnMs > 999
            LnTt = LnTt + 1
            LnMs = LnMs - 1000
        Endif
    Endif
    Return Ttoc(LnTt, 3) + '.' + Padl(LnMs, 3, '0')
Endfunc

Function x_formatTime
    Lparameters tcTime
    If Occurs("T",tcTime)>0
        If Ctod(Getwordnum(tcTime, 1, 'T'))<Date()
            Messagebox("日期数据不能小于当时日期",16+0,"停止")
            Return .F.
        Else
            tcTime = Getwordnum(tcTime, 2, 'T')
        Endif
    Endif
    If Occurs(".",tcTime)>1 Or Occurs(":",tcTime)>2 Or Occurs("-",tcTime)>1 Or Occurs("+",tcTime)>1 Or Occurs("+-",tcTime)>0 Or Occurs("-+",tcTime)>0
        Messagebox("输入数据格式错误",16+0,"停止")
        Return .F.
    Endif
    lcTm = Ltrim(Alltrim(Getwordnum(tcTime, 1, '.')), '-')
    lcTm = Ltrim(lcTm, '+')
    lcTm = Replicate ("0:",2-Occurs(":",lcTm))+lcTm
    lcMs = Getwordnum(tcTime, 2, '.')
    Publ ArTime
    Dimension ArTime[4]
    ArTime[1] = Cast(Getwordnum(LcTm, 1, ':') As I)
    ArTime[2] = Cast(Getwordnum(LcTm, 2, ':') As I)
    ArTime[3] = Cast(Getwordnum(LcTm, 3, ':') As I)
    ArTime[4] = Cast(LcMs As I)
    Return @ArTime
Endfunc


[此贴子已经被作者于2022-7-9 15:06编辑过]

2022-07-09 12:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-509515-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.056439 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved