Author Topic: (challenge) convert Julian date to ddmmyyyy  (Read 10905 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) convert Julian date to ddmmyyyy
« on: September 02, 2004, 11:50:57 AM »
Create an autolisp program using Meeus's version of converting a Julian
date to dd mm yyyy. The program shall accept one argument (Julian date)
and return the converted Julian date in in the form of a string and
format of dd/mm/yyyy.

Let JD = (getvar "TDCREATE")


1. Add .5 to the JD and let Z = integer part of (JD+.5) and F the
      fractional part F = (JD+.5)-Z

2. If Z < 2299161, take A = Z

      If Z >= 2299161, calculate alpha = INT((Z-1867216.25)/36524.25)
      and A = Z + 1 + alpha - INT(alpha/4).

3. Then calculate:

      B = A + 1524
      C = INT( (B-122.1)/365.25)
      D = INT( 365.25*C )
      E = INT( (B-D)/30.6001 )

The day of the month dd (with decimals) is:
 
     dd = B - D - INT(30.6001*E) + F

The month number mm is:

     mm = E - 1, if E < 13.5
or
     mm = E - 13, if E > 13.5

The year yyyy is:

     yyyy = C - 4716   if mm > 2.5
or
     yyyy = C - 4715   if mm < 2.5


An example from Meeus' book is for JD = 2436116.31

     JD + 0.5 = 2436116.81, so

         Z = 2436116

         F = 0.81

     alpha = INT((2436116 - 1867216.25)/36524.25 ) = 15

         A = 2436116 + 1 + 15 - INT(15/4) = 2436129

Then
         B = 2437653
         C = 6673
         D = 2437313
         E = 11

So, dd = 4.81, mm = E-1 = 10, and yyyy = C-4716 = 1957, so the date
is:

     Oct 4.81, 1957
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(challenge) convert Julian date to ddmmyyyy
« Reply #1 on: September 02, 2004, 12:02:54 PM »
What?! :horror:
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) convert Julian date to ddmmyyyy
« Reply #2 on: September 02, 2004, 12:14:13 PM »
What........... *shrug*
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(challenge) convert Julian date to ddmmyyyy
« Reply #3 on: September 02, 2004, 12:26:11 PM »
I understood like ...ONE word out of that.

Are those instructions on how to convert to ddmyy format? or are they just ment to make me look stupid?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) convert Julian date to ddmmyyyy
« Reply #4 on: September 02, 2004, 12:31:54 PM »
Quote from: Se7en
I understood like ...ONE word out of that.

Are those instructions on how to convert to ddmyy format?

Yes, it's really quite easy.

Quote from: Se7en muttered
or are they just ment to make me look stupid?

Well if I can do it ....................
TheSwamp.org  (serving the CAD community since 2003)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challenge) convert Julian date to ddmmyyyy
« Reply #5 on: September 02, 2004, 02:15:10 PM »
I tried to make it work with adding the 0.5 to the julian date, but I kept getting the wrong day, after removing it the day came out correct...
I know the theory behind adding the 0.5, and since in lisp, the FIX function does not round, it is not needed.

Here is my contribution....

Code: [Select]

(defun GDate( JD )
  (setq Z (fix JD)
ALPHA (fix(/(- Z 1867216.25)36524.25))
A (if (< Z 2299161)
   Z
   (- (+ Z 1 ALPHA)(fix (/ ALPHA 4)))
 )
B (+ A 1524)
C (fix(/(- B 122.1) 365.25))
        D (fix(* 365.25 C))
        E (fix(/(- B D)30.6001))
F (- JD (fix JD))
        DD(- B D (fix (* E 30.6001)))
        MM(atoi
   (rtos
     (if (> 13.5 E)
       (- E 1)
       (- E 13)
              )
     2
     0
   )  
 )
        YYYY(if (< 2.5 MM)
     (- C 4716)
     (- C 4715)
   )
    )
    (cond
      ((= MM 1)(setq MM "January"))
      ((= MM 2)(setq MM "February"))
      ((= MM 3)(setq MM "March"))
      ((= MM 4)(setq MM "April"))
      ((= MM 5)(setq MM "May"))
      ((= MM 6)(setq MM "June"))
      ((= MM 7)(setq MM "July"))
      ((= MM 8)(setq MM "August"))
      ((= MM 9)(setq MM "September"))
      ((= MM 10)(setq MM "October"))
      ((= MM 11)(setq MM "November"))
      ((= MM 12)(setq MM "December"))
      (T (setq MM (rtos MM 2 0)))
    )
    (alert (strcat MM " "(rtos (fix DD) 2 0)", "(rtos YYYY 2 0)))
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CADaver

  • Guest
(challenge) convert Julian date to ddmmyyyy
« Reply #6 on: September 02, 2004, 02:37:34 PM »
Code: [Select]
(setq pldate (MENUCMD "M=$(EDTIME, $(GETVAR, DATE),DD-MON-YY HH:MMam/pm)"))

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) convert Julian date to ddmmyyyy
« Reply #7 on: September 02, 2004, 02:44:12 PM »
Quote from: Keith
I tried to make it work with adding the 0.5 to the julian date, but I kept getting the wrong day

this *seems* to work for me. could be just an illusion though.
Code: [Select]

(setq z  (fix (+ jd 0.5))
f (- jd z)
alpha (fix (/ (- z 1867216.25) 36524.25))
)
TheSwamp.org  (serving the CAD community since 2003)

David Bethel

  • Swamp Rat
  • Posts: 656
(challenge) convert Julian date to ddmmyyyy
« Reply #8 on: September 02, 2004, 03:04:46 PM »
I have the Julian conversion that came with R12 by Kelvin Throop dated 1994.  I also have 1 modified by Duff Kirkland and John Walker dated 1993.

The long 1 is very interesting reading.  Both became very moot with the introduction of Diesel.  -David

15 KB

http://www.davidbethel.com/lisp/julian.lsp
R12 Dos - A2K

CarlB

  • Guest

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challenge) convert Julian date to ddmmyyyy
« Reply #10 on: September 02, 2004, 06:50:48 PM »
If all you are intersested in is the date, then why not use:
Code: [Select]

(setq longdate (rtos (getvar "date") 2 0))
(setq YYYY (substr longdate 1 4)
        MM (substr longdate 5 2)
        DD (substr longdate 7 2)
)
(princ (substr MM "-" DD "-" YYYY))
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) convert Julian date to ddmmyyyy
« Reply #11 on: September 02, 2004, 08:53:23 PM »
The whole point of this thread was to get all the hackers (newbies mainly) to write a program using the forumla listed. I wasn't looking for information, it was simply a challenge.
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(challenge) convert Julian date to ddmmyyyy
« Reply #12 on: September 02, 2004, 09:22:59 PM »
I was thinking that this would be a good one for someone to get their feet wet with. I actualy didnt get to any code at lunch like i thought i would today, but you basicly did all the work already with those instructions (yes, i have since re-read them.) in the first post. (Although, i still think they were worded in a way intended to make me look stupid.  ...This is a setup isnt it!?)

Anyways, I want to try to get some code down on paper tomorow at lunch. (Im still in a Microstation job so I cant hide the fact that im writing a lisp. :P)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(challenge) convert Julian date to ddmmyyyy
« Reply #13 on: September 02, 2004, 10:30:21 PM »
uStation; ackk.

We've lost him to the dark side folks!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
(challenge) convert Julian date to ddmmyyyy
« Reply #14 on: September 03, 2004, 08:14:42 AM »
Speaking of MickeyStation, there's this guy here who keeps singing the praises of MS and keeps calling Autocad archaic. Personally, I think he's full of crap and doesn't know what he's talking about, but then I've never used MS, nor do I want to. His biggest complaint is that he can't, in Autocad, copy multiple items from the start and he keeps telling us that we should put our dimensions in paperspace, because that's the way they did it when he used MS. My guess is, he hasn't used autocad since release 14. I'm just glad he's not in the cad department. He's a project manager.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(challenge) convert Julian date to ddmmyyyy
« Reply #15 on: September 03, 2004, 08:18:36 AM »
Heh, I had a job using only AutoCAD about a year ago now (Actually i think about 8-9 months ago but... *Ehh*) and i loved it (well sorta), but then i got let go because of cut backs. (BTW, i just got an email from a friend at that co. and he said that 4 more got the axe. ...?!)

Now i work for a co. that uses MicroCrap and AutoCAD. (I hate every min of my day.)


*As the conversation ends, we can hear Se7en mutter away at his computer:
...Stupid computer program! just fricken snap to the line! ...Oh you dirty bastard! What did you do now. HEY, where ...err...*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
(challenge) convert Julian date to ddmmyyyy
« Reply #16 on: September 03, 2004, 08:25:28 AM »
Thanks for the laugh, Se7en. That'll be the beginning of a good day for me.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(challenge) convert Julian date to ddmmyyyy
« Reply #17 on: September 03, 2004, 08:28:14 AM »
My agony is your enjoyment?! ...Glad i could be of service.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(challenge) convert Julian date to ddmmyyyy
« Reply #18 on: September 03, 2004, 09:44:04 AM »
He obviously needs to be slapped sober.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(challenge) convert Julian date to ddmmyyyy
« Reply #19 on: September 03, 2004, 10:33:16 AM »
The people i work with *please, please, please* or Daron *Oh for the love of Gawd, say 'yes'*?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CADaver

  • Guest
(challenge) convert Julian date to ddmmyyyy
« Reply #20 on: September 03, 2004, 11:13:49 AM »
Quote from: Daron
His biggest complaint is that he can't, in Autocad, copy multiple items from the start
wha???

Quote from: Daron
and he keeps telling us that we should put our dimensions in paperspace, because that's the way they did it when he used MS.
While we place all annotation in PS, and IMMHO, that's a more efficient method, it is not required.  As far as mickeystation goes, it doesn't have paperspace, it uses a heavy-handed workaround called sheet models.  They are not really part of the file, but a separate file(s) that is basically a large PITB.

daron

  • Guest
(challenge) convert Julian date to ddmmyyyy
« Reply #21 on: September 03, 2004, 01:15:06 PM »
Se7en? What are you talking about? You couldn't slap me sober, I always am. Now, the MS lover, him he does need to be slapped sober as well as the people you work for.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challenge) convert Julian date to ddmmyyyy
« Reply #22 on: September 03, 2004, 09:46:24 PM »
Quote from: Daron
Se7en? What are you talking about? You couldn't slap me sober, I always am.

Daron ... That would have been MP
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
(challenge) convert Julian date to ddmmyyyy
« Reply #23 on: September 07, 2004, 08:32:38 AM »
What??? MP's the one who said it. Maybe I need to take an extra day off.