View unanswered posts | View active topics It is currently Tue Apr 21, 2026 10:04 am



Reply to topic  [ 15 posts ] 
 date parsing snippet needed for the date on daily logs. 
Author Message
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post date parsing snippet needed for the date on daily logs.
this is what i thru together but I have no way to test it.

Its for a news reader I wrote yesterday because the one thats out their doesnt work for my corpies.
btw I will release the rest of the code i soon as its debudded a little.

On another note anyone who wants to actually TEST new scripts should ICQ me.



Code:
:parse_date
cuttext $the_date $month 1 2
cuttext $the_date $day 4 2
cuttext $the_date $year 7 2

if ($day = "01")
goto :get_month_array

if ($month < 10)
setvar $month ($month - 1)
setvar $month ("0" & $month)
else
subtract $month 1
end

setvar $day $month_array[$month]
setvar $the_date ($month & "/" & $day & "/" & $year)
return
end

if ($day < 10)
setvar $day ($day - 1)
setvar $day ("0" & $day)
end
setvar $the_date ($month & "/" & ($day - 1) & "/" & $year)
return

:get_month_array
setvar $month_array[1] "31"
if ($year = "20")
setvar $month_array[2] "29"
else
setvar $month_array[2] "28"
end
setvar $month_array[3] "31"
setvar $month_array[4] "30"

setvar $month_array[5] "31"
setvar $month_array[6] "30"
setvar $month_array[7] "31"
setvar $month_array[8] "31"

setvar $month_array[9]  "30"
setvar $month_array[10] "31"
setvar $month_array[11] "30"
setvar $month_array[12] "31"
return

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Tue Feb 26, 2008 2:33 pm
Profile ICQ YIM
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: date parsing snippet needed for the date on daily logs.
I know this type of detail isn't probably justified for a script, but to calculate a leap year:

If it is evenly divisible by 4 and not evenly divisible by 100, it is a leap year.

If it is evenly divisible by 4 and is also evenly divisible by 400, it is a leap year.

If it is evenly divisible by 4 and also evenly divisible by 100 and also evenly divisible by 400, it is a leap year.

However, if it is evenly divisible by 4 and also evenly divisible by 100 and not further evenly divisible by 400, then it is not a leap year.

It is also more of a pain than it is worth.

[Edit]I forgot to say the information above is from a website and I didn't get the URL for attribution[/EDIT]

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Last edited by Promethius on Wed Feb 27, 2008 1:12 am, edited 1 time in total.



Tue Feb 26, 2008 9:06 pm
Profile ICQ
Gameop
User avatar

Joined: Tue Sep 25, 2007 7:27 pm
Posts: 530
Location: Long Island
Unread post Re: date parsing snippet needed for the date on daily logs.
TWX doesn't have a MOD function does it?

_________________
If you have a building game, they will come...

Proud Sysop of ICE9 TWGS
Home of Building and Non Regulated Games
http://www.oregonsouth.com/ice9
telnet://ice9-tw.com:2002


Tue Feb 26, 2008 10:23 pm
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: date parsing snippet needed for the date on daily logs.
V'Ger wrote:
TWX doesn't have a MOD function does it?


Not that I am aware of. You would have to do a work around for it. I think you could use setprecision and then check the value - prob not 100% accurate that way.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Wed Feb 27, 2008 1:09 am
Profile ICQ
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: date parsing snippet needed for the date on daily logs.
Best way to work around it, is to make a simple subroutine that essentially does what computers do anyways..

10 MOD 4 = 2

Translated into TWX-Scripting:
Code:
# 10 MOD 4
setVar $DV 4
setVar $OP 10
gosub :Mod

echo "**" $remainder "**"
halt

:mod
setVar $remainder 0
setVar $PRE 0
setVar $PST 0
:again
setVar $PST $PRE
add $PRE $DV
if ($PRE < $OP)
goto :again
end
if ($PRE = $OP)
setVar $remainder 0
return
end
if ($PRE > $OP)
setVar $remainder ($OP - $PST)
return
end


..off the top of my head. someone can prob make a better routine.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Thu Feb 28, 2008 7:26 am
Profile ICQ YIM
Gameop
User avatar

Joined: Tue Sep 25, 2007 7:27 pm
Posts: 530
Location: Long Island
Unread post Re: date parsing snippet needed for the date on daily logs.
Wow, that is far much easier than what I was trying. Thanks LS.

_________________
If you have a building game, they will come...

Proud Sysop of ICE9 TWGS
Home of Building and Non Regulated Games
http://www.oregonsouth.com/ice9
telnet://ice9-tw.com:2002


Thu Feb 28, 2008 9:41 am
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: date parsing snippet needed for the date on daily logs.
I like LoneStar's snippet for finding mod as it gives the actual value. The setprecision method would basically return if 10 mod 4 had a remainder and is not 100% accurate since accuracy is determined by the setprecison number:

# 10 mod 4

setVar $dv 4
setVar $op 10

setprecision 4
divide $op $dv
setVar $tmpOp $op
setprecision 0
multiply $tmpOp 1
setprecision 4

if ($tmpOp <> $op)
echo "**Remainder Exists: "
else
echo "**No remainder exists:"
end

echo "*$op = " $op " $tmpOp = " $tmpOp

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Thu Feb 28, 2008 1:08 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: date parsing snippet needed for the date on daily logs.
You know I'm always up for a math or script challenge, so when a thread presents both... I can't resist.

setVar $numerator 10
setVar $denominator 4
setVar $mod ($numerator - ($denominator * ($numerator / $denominator)))
echo "*" $numerator " mod " $denominator " = " $mod "*"

And incidently, I did once write a routine that calculated the number of days since a given date, including proper leap year calculations, which I could possibly dig up if there is interest. It was originally written for fig/shield/hold calculations.

+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Feb 28, 2008 7:39 pm
Profile WWW
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: date parsing snippet needed for the date on daily logs.
ElderProphet wrote:
You know I'm always up for a math or script challenge, so when a thread presents both... I can't resist.

setVar $numerator 10
setVar $denominator 4
setVar $mod ($numerator - ($denominator * ($numerator / $denominator)))
echo "*" $numerator " mod " $denominator " = " $mod "*"

And incidently, I did once write a routine that calculated the number of days since a given date, including proper leap year calculations, which I could possibly dig up if there is interest. It was originally written for fig/shield/hold calculations.

+EP+


Very nice indeed. I know there was interest some time back on calculating what the cost of figs/shields would be in a certain number of days. I don't think that was ever really addressed at least in regards to a twx script.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Fri Feb 29, 2008 1:11 am
Profile ICQ
Lieutenant J.G.
User avatar

Joined: Sun Mar 13, 2005 3:00 am
Posts: 387
Location: USA
Unread post Re: date parsing snippet needed for the date on daily logs.
You know I'm always up for a math or script challenge, so when a thread presents both... I can't resist.

setVar $numerator 10
setVar $denominator 4
setVar $mod ($numerator - ($denominator * ($numerator / $denominator)))
echo "*" $numerator " mod " $denominator " = " $mod "*"

And incidently, I did once write a routine that calculated the number of days since a given date, including proper leap year calculations, which I could possibly dig up if there is interest. It was originally written for fig/shield/hold calculations.

+EP+

Come on now EP

How hard is this ?
function CmdMOD(Script : TObject; Params : array of TCmdParam) : TCmdAction;
var
F1,
F2 : Integer;
begin
// CMD: MOD var <value>
// Modula a value to a variable

ConvertToFloat(Params[0].Value, TScript(Script).DecimalPrecision, F1);
ConvertToFloat(Params[1].Value, TScript(Script).DecimalPrecision, F2);
if (TScript(Script).DecimalPrecision = 0) then
Params[0].Value := IntToStr(Trunc(F1 MOD F2))
else
Params[0].Value := FormatFloatToStr(F1 MOD F2, TScript(Script).DecimalPrecision);

Result := caNone;
end;

Hacked in less than 5 minutes straight out of your source code. This particular function used was the ADD. All I changed was the operator from + to MOD.
But I have not included a check for ZERO as this could throw a Division by zero error.

Maniac AKA StudleyManiac AKA Missing In Action due to internet connectivity problems.

_________________
Find out just what any people will quietly submit to and you have the exact measure of the injustice and wrong which will be imposed on them. Frederick Douglas


Fri Feb 29, 2008 3:27 am
Profile ICQ
Lieutenant J.G.
User avatar

Joined: Sun Mar 13, 2005 3:00 am
Posts: 387
Location: USA
Unread post Re: date parsing snippet needed for the date on daily logs.
After thinking further down the road, about how it might be possible to change/add more commands to TWXProxy Xide has done most of the work.
The previous example I posted should NOT use the "Add" operand it should use the Divide command format as he already checks for division by zero.

Yes I know that a MOD command would primarily be used on integers but for a quick 5 minute fix I think the code posted above could be integrated into TWXProxy just by adding the appropiate AddCommand(cmdMOD......) to the TList that Xide/EP uses for lookup.

If it works already with a certain data type and all you change is the operator then the only bugs you might introduce will be in the implementation of adding a new Command to the list.

Unless your like me and pick the wrong example to begin with....

_________________
Find out just what any people will quietly submit to and you have the exact measure of the injustice and wrong which will be imposed on them. Frederick Douglas


Fri Feb 29, 2008 3:39 am
Profile ICQ
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post Re: date parsing snippet needed for the date on daily logs.
hey everyone ...thanks for Not answering the question and/or providing and useful info.

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Sat Mar 01, 2008 3:09 pm
Profile ICQ YIM
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: date parsing snippet needed for the date on daily logs.
Parrothead wrote:
hey everyone ...thanks for Not answering the question and/or providing and useful info.


Sorry PH, my fault on seeing the part in your script that caused me to post about the calculation for leap years. Kinda hijacked the thread a bit.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sat Mar 01, 2008 7:53 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: date parsing snippet needed for the date on daily logs.
You didn't actually ask a question.

Below is my absolute date script, which may prove useful. NB: directions for use as an include are in the comments.

+EP+
Code:
# AbsoluteDate.ts by ElderProphet
#
# Here is the year basis:
# Normal year = 365 days
# 4 Years = 1461, which is (365*4)+1
# 100 Years = 36524, which is (1461*25)-1
# 400 Years = 146097, which is (36524*4)+1
#
# For include usage, set $absoluteDate~date month/day/year, E.g. 2/29/2004
#   then gosub :absoluteDate~absDate
#   The absolute date will be $absoluteDate~absDate

:start
echo ANSI_15 "*Enter Date (mm/dd/yyyy), or just press ENTER to calculate today's Absolute Date."
getConsoleInput $input
if ($input = "") or ($input = 0)
   getDate $date
else
   setVar $date $input
end
gosub :absDate
echo ANSI_10 "*" $input " : " ANSI_11 "AbsoluteDate=" $absDate "*"
goto :start

:absDate
setVar $absDate 0
replaceText $date "/" " "
getWord $date $month 1
getWord $date $day 2
getWord $date $year 3

# Determine the number of days for all completed years
while ($year > 400)
   add $absDate 146097
   subtract $year 400
end
while ($year > 100)
   add $absDate 36524
   subtract $year 100
end
while ($year > 4)
   add $absDate 1461
   subtract $year 4
end
# And for leap years, before and after 2/29
if ($year = 4) and ($month > 2)
   add $absDate 1
end
while ($year > 0)
   add $absDate 365
   subtract $year 1
end

# Determine the number of days for all completed months
if ($month = 2)
   add $absDate 31
elseif ($month = 3)
   add $absDate 59
elseif ($month = 4)
   add $absDate 90
elseif ($month = 5)
   add $absDate 120
elseif ($month = 6)
   add $absDate 151
elseif ($month = 7)
   add $absDate 181
elseif ($month = 8)
   add $absDate 212
elseif ($month = 9)
   add $absDate 243
elseif ($month = 10)
   add $absDate 273
elseif ($month = 11)
   add $absDate 304
elseif ($month = 12)
   add $absDate 334
end

# Add the days of the current month
add $absDate $day
return

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Sun Mar 02, 2008 7:30 pm
Profile WWW
Gameop
User avatar

Joined: Thu Mar 08, 2001 3:00 am
Posts: 886
Location: USA
Unread post Re: date parsing snippet needed for the date on daily logs.
ElderProphet wrote:
You didn't actually ask a question.


QFT

_________________
twgs : telnet://twgs.thereverend.org:5023
web : http://www.thereverend.org
games : http://www.thestardock.com/twgssearch/i ... verend.org
helper : http://svn.thereverend.org:8080/revhelper/


Mon Mar 03, 2008 3:57 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 posts ] 

Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.