Author Topic: Time difference..  (Read 4672 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
Time difference..
« on: November 02, 2006, 09:25:31 AM »
Hi all..

i'm trying to find a way to get the difference between the curent date.....andsome other date.

eg:

Code: [Select]
(load "julian")
(setq cdate (rtos (getvar "CDATE") 2 6)
Year (read (substr cdate 1 4))
Month (read (substr cdate 5 2))
Day (read (substr cdate 7 2))
Hour (read (substr cdate 10 2))
Minute (read (substr cdate 12 2))
Sec (read (substr cdate 14 2)))

(setq year1 2006
month1 12
day1 5
Hour1 9
minute1 55
sec1 32)


(setq d1 (-
   (ctoj Year Month Day Hour Minute Sec)
   (ctoj Year1 Month1 Day1 Hour1 Minute1 Sec1)
)
)

(jtoc d1)

I've tried this with Julian..but...maybe I don't realy understand how it work..

I just need to get the time difference between 2 files...
eg:
Code: [Select]
(setq File1TIME (vl-file-systime "c:\\file1.dwg"))
(setq File2TIME (vl-file-systime "c:\\file2.dwg"))

In Hour, day minutes....don't matter...just need difference..(- A B)
any idea how ?
« Last Edit: November 02, 2006, 09:28:42 AM by Andrea »
Keep smile...

Derwin

  • Guest
Re: Time difference..
« Reply #1 on: November 02, 2006, 05:37:09 PM »
hi,
partial solution:

1. get/load "doslib16.arx"

2. Command: (setq a (cdr(assoc '"TEST.AAA" (dos_filedate "C:\\test.aaa"))))
2.00408e+007

3.Command: (setq b (cdr(assoc '"TEST.BBB" (dos_filedate "C:\\test.bbb"))))
2.0061e+007

4.Command: (- a b)
-20221.0

5. (??) duun. acad help talks a bout DIESELs $(edtime), but ive never used that so i dont know where/how it works. something like:
$(edtime (- a b)) will return the difference in a readable date format.

Derwin

  • Guest
Re: Time difference..
« Reply #2 on: November 02, 2006, 07:38:36 PM »
this one works for me:

Code: [Select]
; ----------------------------------------------------------------------------
; memeeng 031106 returns date difference between 2 files.
; based on idea+code from Andrea Andreetti
;
(defun filedatediff ( FNAME1 FNAME2 ) a b aa bb DATE SDATE Year Month Day Hour Minute Sec
  (setq aa (strcase(strcat (vl-filename-base FNAME1)(vl-filename-extension FNAME1) ))
a (cdr(assoc aa (dos_filedate FNAME1)))
bb (strcase(strcat (vl-filename-base FNAME2)(vl-filename-extension FNAME2) ))
b (cdr(assoc bb (dos_filedate FNAME2)))
SDATE (rtos (abs(- a b)) 2 0)
DATE (strcat (substr "00000000" (1+ (strlen SDATE))) SDATE (substr (rtos (- (abs (- a b)) (fix(abs(- a b)))) 2 6) 2)  ))
  (setq Year (read (substr DATE 1 4))
Month (read (substr DATE 5 2))
Day (read (substr DATE 7 2))
Hour (read (substr DATE 10 2))
Minute (read (substr DATE 12 2))
Sec (read (substr DATE 14 2)))
  (princ "\nDATE DIFFERENCE BETWEEN FILES:" )
  (princ (strcat "\nYEARS:  " (itoa Year) ))
  (princ (strcat "\nMONTHS: " (itoa Month) ))
  (princ (strcat "\nDAYS:   " (itoa Day) ))
  (princ (strcat "\nHOURS:  " (itoa Hour) ))
  (princ (strcat "\nMINS:   " (itoa Minute) ))
  (princ (strcat "\nSECS:   " (itoa Sec) ))
  (princ)
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Time difference..
« Reply #3 on: November 02, 2006, 08:35:26 PM »
You may want to check your code ..

The variables need to be local, not as posted ie
Quote
(defun filedatediff ( FNAME1 FNAME2 ) a b aa bb DATE SDATE Year Month Day Hour Minute Sec

The VL-FILENAME-BASE will strip the path, which will cause the routine to fail ... so this may be better

remove the assignment to aa
and use something like 
(setq a (CDAR (DOS_FILEDATE FNAME1)) ....

haven't looked further ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Derwin

  • Guest
Re: Time difference..
« Reply #4 on: November 02, 2006, 08:42:23 PM »
true. the path will be lost.

it was my previous understanding that those variables would be local? ie: one of two syntax's:

(defun BLAH ( PAR1 PAR2 / LOCAL1 LOCAL2)
  ...
)

or

(defun BLAH (PAR1 PAR2) LOCAL1 LOCAL2
  ...
)

or am i wrong??

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Time difference..
« Reply #5 on: November 02, 2006, 08:46:09 PM »
( PAR1 PAR2 / LOCAL1 LOCAL2)

(parameters / local variables ) is correct.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Derwin

  • Guest
Re: Time difference..
« Reply #6 on: November 02, 2006, 09:46:11 PM »
i conceed your point. you are correct. i now have a lot of code to fix..
(no wonder some functions were painfully buggy..)

however it does work with paths, and aa is required as (dos_filedate) returns (("FNAME1.EXT" . 1234.5678)), so aa without a path is required to get to the 1234 bit.

thanks, all is appreciated.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Time difference..
« Reply #7 on: November 02, 2006, 10:18:30 PM »
Try this

Code: [Select]
(setq a (CDAR (DOS_FILEDATE FNAME1)) )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Time difference..
« Reply #8 on: November 02, 2006, 10:22:16 PM »
^^^  This simply isolated the associative part of the data list, rather than needing to change case and use the (assoc .. function .
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Time difference..
« Reply #9 on: November 03, 2006, 10:33:45 AM »
Thanks...

first...
You can't do (- a b)...
eg:
a = 20061103.085156
b = 20061103.092448

(- a b) = 00000000.007292 (00:72:92) <-False

because the Hours, Minutes, and Seconds is based on 60 utnits not 100.

the real result must be  -> 00:33:52
so how 00:72:92 can be -> 00:33:52 ?

same as
month....based on 12 units and not 100
day........based on 28,30 or 31

I think this will be more complicated..

also....why use the DOS_FILEDATE ?

Code: [Select]
(defun getdate ( filename / FileTIME anne mois jour Heure Minute Seconde OUTdate)
;;Capture la Date de sortie (date du fichier)
(setq FileTIME (vl-file-systime filename))
(setq anne (rtos (car FileTIME)))

(setq mois (rtos (cadr FileTIME)))
(if (< (strlen mois) 2) (setq mois (strcat "0" mois)))

(setq jour (rtos (cadddr FileTIME)))
(if (< (strlen jour) 2) (setq jour (strcat "0" jour)))

(setq Heure (rtos (cadddr (cdr FileTIME))))
(if (< (strlen Heure) 2) (setq Heure (strcat "0" Heure)))

(setq Minute (rtos (cadddr (cdr (cdr FileTIME)))))
(if (< (strlen Minute) 2) (setq Minute (strcat "0" Minute)))

(setq Seconde (rtos (cadddr (cdr (cdr (cdr FileTIME))))))
(if (< (strlen Seconde) 2) (setq Seconde (strcat "0" Seconde)))

(setq OUTdate (strcat anne mois jour "." Heure Minute Seconde));;"2006111.114828"
)

 
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Time difference..
« Reply #10 on: November 03, 2006, 05:09:34 PM »
Andrea, from memory,  if one of the documents you are testing is open the (vl-file-systime may fail.

I have not tested your routine, just mentioning this as somethimg you may have to check for.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Time difference..
« Reply #11 on: November 04, 2006, 04:01:07 AM »
revisit ..

Quote
(strcat anne mois jour "." Heure Minute Seconde)) ;;"2006111.114828"

shouldn't this be ;;"20061<another digit in here>11.114828" ?
« Last Edit: November 04, 2006, 04:02:13 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Derwin

  • Guest
Re: Time difference..
« Reply #12 on: November 06, 2006, 12:32:58 AM »
ok, this one just does hours, mins and secs, by converting to seconds, then working back. simple. (and can probably be made smaller..)

the thing that stumped me was the answer you first gave for 33:52 is (i think) wrong. 085156 is 000804 away from 090000, and so
000804 + 002448 => 24+8 : 04+48 => 32:52. (an hour head scratching for that one..)

the year:month:day part will need leapyears (divisible by 400 and 4) and the months(28,30,31). and im not doing that just yet..

Code: [Select]
(defun C:testdatediff ()
  (datediff "20061103.085156" "20061103.092448" )
  (datediff "20061103.080156" "20061103.205448" )
  (datediff "20061103.080156" "20061103.080200" )
  (datediff "20061103.080156" "20061103.090156" )
  (datediff "20061103.085530" "20061103.095520" )
  (datediff "20061103.000000" "20061103.235959" )
  (princ)
)

(defun datediff ( DATEA DATEB / HMSA HMSB HMSD HOURD MIND SECD )
  (setq HMSA (+  (* 3600 (read(substr DATEA 10 2)))
(*   60 (read(substr DATEA 12 2)))
(*    1 (read(substr DATEA 14 2))) )
HMSB (+  (* 3600 (read(substr DATEB 10 2)))
(*   60 (read(substr DATEB 12 2)))
(*    1 (read(substr DATEB 14 2))) )
HMSD (abs(- HMSA HMSB))
HOURD (/ HMSD 3600)
MIND  (/ (- HMSD (* HOURD 3600)) 60)
SECD  (- HMSD (* HOURD 3600) (* MIND 60))
  )
  (princ "\nHOUR:MIN:SEC Difference between " )(princ DATEA)(princ " and ")(princ DATEB)(princ " is ")
  (princ (strcat (itoa HOURD) ":" (itoa MIND) ":" (itoa SECD) ))
  (princ)
)


Andrea

  • Water Moccasin
  • Posts: 2372
Re: Time difference..
« Reply #13 on: November 06, 2006, 02:20:02 PM »
revisit ..

shouldn't this be ;;"20061<another digit in here>11.114828" ?


Thats why I put the " IF " syntax.
Also your right, the (vl-file-systime....not working if the file is open..
but not important in the routine i'm trying to make...
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Time difference..
« Reply #14 on: November 06, 2006, 06:20:41 PM »
There it is....
a  section of my program...

Code: [Select]
(defun CADreport (/ loginname GEN_VERS_current ACADver e FileTIME anne jour
    Heure Minute Seconde OUTdate)

(setq loginname (getvar "LOGINNAME"))
(setq GEN_VERS_current (getvar "acadver"))
(if (vl-string-search "15." GEN_VERS_current)(setq ACADver "2002"))
(if (vl-string-search "16.0" GEN_VERS_current)(setq ACADver "2004"))
(if (vl-string-search "16.1" GEN_VERS_current)(setq ACADver "2005"))
(if (vl-string-search "16.2" GEN_VERS_current)(setq ACADver "2006"))
(if (vl-string-search "17.0" GEN_VERS_current)(setq ACADver "2007"))

;;si le fichier n'existe pas
(if (not (findfile (strcat "c:\\CADtime" ACADver".rpt")))
(progn
(setq e (open (strcat "c:\\CADtime" ACADver".rpt") "w"))
(write-line (strcat "IN -" (rtos (getvar "CDATE") 2 6)) e)
;;(close e)
)
(progn 
;;Capture la Date de sortie (date du fichier)
(setq FileTIME (vl-file-systime (strcat "c:\\CADtime" ACADver".rpt")))
(setq anne (rtos (car FileTIME)))
(setq mois (rtos (cadr FileTIME)))
(if (< (strlen mois) 2) (setq mois (strcat "0" mois)))
(setq jour (rtos (cadddr FileTIME)))
(if (< (strlen jour) 2) (setq jour (strcat "0" jour)))
(setq Heure (rtos (cadddr (cdr FileTIME))))
(if (< (strlen Heure) 2) (setq Heure (strcat "0" Heure)))
(setq Minute (rtos (cadddr (cdr (cdr FileTIME)))))
(if (< (strlen Minute) 2) (setq Minute (strcat "0" Minute)))
(setq Seconde (rtos (cadddr (cdr (cdr (cdr FileTIME))))))
(if (< (strlen Seconde) 2) (setq Seconde (strcat "0" Seconde)))
(setq OUTdate (strcat anne mois jour "." Heure Minute Seconde));;"2006111.114828"
(setq e (open (strcat "c:\\CADtime" ACADver".rpt") "a"))
(write-line (strcat "OUT-" OUTdate) e)
(write-line (strcat "IN -" (rtos (getvar "CDATE") 2 6)) e)
)))

(CADreport)

This program put in a txt file the IN and OUT of AutoCAD USE...by version.

The problem is that I can't found a way to calculate the spent time.

résult...=
Keep smile...