Gregorian to hijri and viceversa javascript

I have a Javascript for a Hijri / Gregorian calendar.
I need to get it into Adobe Acrobat PDF.
The business requirements for this are easy. Just take the script i give you and get it to work in Adobe Acrobat PDF.
The technical side is tricky. I haven't been able to make it work. When I do it, the conversion works 1 time when you first open the document. then, it only works one way after that. (from gregorian to hijri, never the other way around.)
1. This MUST be done in Acrobat XI, Not LiveCycle.
2. I'm using Adobe Acrobat XI Pro. I can't use any other version right now. So this must be able to work on XI and then people need to be able to open and execute this in Reader.
Here is the code I have written from a HTM file..
<SCRIPT LANGUAGE="JavaScript">
  function setDateToToday()
    var today = new Date();
    var y = today.getYear();
    var y = today.getYear();
    if (y < 1000) {
        y += 1900;
    document.myform.CYear.value = y;
    document.myform.CMonth.selectedIndex = today.getMonth();
    document.myform.CDay.value = today.getDate();
// Travis added the following method call to fix the bug where the Hijri date was not set to today by default   
    chrToIsl(0);
//  LEAP_GREGORIAN  --  Is a given year in the Gregorian calendar a leap year ?
function leap_gregorian(year)
    return ((year % 4) == 0) &&
            (!(((year % 100) == 0) && ((year % 400) != 0)));
//  GREGORIAN_TO_JD  --  Determine Julian day number from Gregorian calendar date
function gregorian_to_jd(year, month, day)
    var GREGORIAN_EPOCH = 1721425.5;
    return (GREGORIAN_EPOCH - 1) +
           (365 * (year - 1)) +
           Math.floor((year - 1) / 4) +
           (-Math.floor((year - 1) / 100)) +
           Math.floor((year - 1) / 400) +
           Math.floor((((367 * month) - 362) / 12) +
           ((month <= 2) ? 0 :
                               (leap_gregorian(year) ? -1 : -2)
           ) +
           day);
function mod(a, b)
    return a - (b * Math.floor(a / b));
function jd_to_gregorian(jd) {
    var wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad,
        yindex, dyindex, year, yearday, leapadj;
    var GREGORIAN_EPOCH = 1721425.5;
    wjd = Math.floor(jd - 0.5) + 0.5;
    depoch = wjd - GREGORIAN_EPOCH;
    quadricent = Math.floor(depoch / 146097);
    dqc = mod(depoch, 146097);
    cent = Math.floor(dqc / 36524);
    dcent = mod(dqc, 36524);
    quad = Math.floor(dcent / 1461);
    dquad = mod(dcent, 1461);
    yindex = Math.floor(dquad / 365);
    year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex;
    if (!((cent == 4) || (yindex == 4))) {
        year++;
    yearday = wjd - gregorian_to_jd(year, 1, 1);
    leapadj = ((wjd < gregorian_to_jd(year, 3, 1)) ? 0
                  (leap_gregorian(year) ? 1 : 2)
    month = Math.floor((((yearday + leapadj) * 12) + 373) / 367);
    day = (wjd - gregorian_to_jd(year, month, 1)) + 1;
          document.myform.CDay.value = day;
          document.myform.CMonth.value = month;
          document.myform.CYear.value = year;
function intPart(floatNum){
if (floatNum< -0.0000001){
           return Math.ceil(floatNum-0.0000001)
return Math.floor(floatNum+0.0000001)
function weekDay(wdn){
// Stubbed this out because we have no interest in showing the days of the week.
  return ""  }
function chrToIsl(NumberofDays) {
          //alert("Month:" + document.myform.CMonth.value)
          d=parseInt(document.myform.CDay.value)
          m=parseInt(document.myform.CMonth.value)
          y=parseInt(document.myform.CYear.value)
                                                  if ((y>1582)||((y==1582)&&(m>10))||((y==1582)&&(m==10)&&(d>14)))
                                                            jd=intPart((1461*(y+4800+intPart((m-14)/12)))/4)+intPart((3 67*(m-2-12*(intPart((m-14)/12))))/12)-
          intPart( (3* (intPart(  (y+4900+    intPart( (m-14)/12)     )/100)    )   ) /4)+d-32075
                                                            else
                                                            jd = 367*y-intPart((7*(y+5001+intPart((m-9)/7)))/4)+intPart((275*m)/9)+d+1729777
                                                  jd = jd + NumberofDays
                                                  //Stubbed out the weekday/epoch names below to remove them from the HTML page.  jd = epoch time wd = weekday
                                                  //document.myform.JD.value=jd
                                                  //document.myform.wd.value=weekDay(jd%7)
                                                  l=jd-1948440+10632
                                                  n=intPart((l-1)/10631)
                                                  l=l-10631*n+354 
                                                  j=(intPart((10985-l)/5316))*(intPart((50*l)/17719))+(intPart(l/5 670))*(intPart((43*l)/15238))
                                                  l=l-(intPart((30-j)/15))*(intPart((17719*j)/50))-(intPart(j/16)) *(intPart((15238*j)/43))+29
                                                  m=intPart((24*l)/709)
                                                  d=l-intPart((709*m)/24)
                                                  y=30*n+j-30
          jd_to_gregorian(jd)
          document.myform.HDay.value=d
          document.myform.HMonth.value=m
          document.myform.HYear.value=y
function islToChr( NumberofDays) {
          d=parseInt(document.myform.HDay.value)
          m=parseInt(document.myform.HMonth.value)
          y=parseInt(document.myform.HYear.value)
          jd=intPart((11*y+3)/30)+354*y+30*m-intPart((m-1)/2)+d+1948440-385
          jd = jd + NumberofDays
          //Stubbed out the weekday/epoch names below to remove them from the HTML page.  jd = epoch time wd = weekday
          //document.myform.JD.value=jd
          //document.myform.wd.value=weekDay(jd%7)
                                                  if (jd> 2299160 )
                                                             l=jd+68569
                                                             n=intPart((4*l)/146097)
                                                            l=l-intPart((146097*n+3)/4)
                                                             i=intPart((4000*(l+1))/1461001)
                                                            l=l-intPart((1461*i)/4)+31
                                                             j=intPart((80*l)/2447)
                                                            d=l-intPart((2447*j)/80)
                                                            l=intPart(j/11)
                                                            m=j+2-12*l
                                                            y=100*(n-49)+i+l
                                                  else
                                                             j=jd+1402
                                                             k=intPart((j-1)/1461)
                                                             l=j-1461*k
                                                             n=intPart((l-1)/365)-intPart(l/1461)
                                                             i=l-365*n+30
                                                            j=intPart((80*i)/2447)
                                                            d=i-intPart((2447*j)/80)
                                                            i=intPart(j/11)
                                                            m=j+2-12*i
                                                            y=4*k+n+i-4716
          document.myform.CDay.value=d
          document.myform.CMonth.value=m
          document.myform.CYear.value=y
</SCRIPT>
    <FORM NAME="myform">
<strong>gregorian</strong>
  <select size="1" name="CMonth" onChange="chrToIsl(0);">
    <option selected value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
  </select>
<select size="1" name="CDay"  onChange="chrToIsl(0);">
    <option selected value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
  </select>
<INPUT TYPE="text" NAME="CYear" VALUE="" SIZE="4" onChange="chrToIsl(0);" onKeyUp="chrToIsl(0);" >
  </p>
<strong>hijri</strong>
<select size="1" name="HMonth" onChange="islToChr(0);">
    <option selected value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
  </select>
<select size="1" name="HDay" onChange="islToChr(0);">
    <option selected value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
  </select>
<INPUT TYPE="text" NAME="HYear" VALUE="1430" SIZE="4" onChange="islToChr(0);" onKeyUp="islToChr(0);">
<script>
setDateToToday();
</script>
I just need the functionality if it can be achieved with a better script.

Hi,
Issue 1 - it doesn't convert to Hijri date, only Julian date for Hijri (doesn't show the Hijri date but does show two Gregorian dates).
I am sorry I don't actually know how to convert between the dates, I only used the code that you provided in your initial post and called that from the Acrobat PDF form,
The sample I provided is how to call the code above using Acrobat.
Issue 2 -  I want to be able to have the dates default (if blank) to today's date
That is easy enough to do in that you just use JavaScript to get the current date and time using the Date object.
And it can convert dynamically as you could just attach the code to the change or exit events of the objects that you are using to select the date and run the code.
I kept my sample simple and used buttons so it is easy for everyone to see how the code is called as you can look at the preferences of each button to see the JavaScript that is used.
Regards
Malcolm

Similar Messages

  • Open PDF from database in a browser and run Javascript within PDF

    What we're trying to accomplish is to query a PDF in the database and open the PDF in the browse. Once opened if a user click on a link to open another PDF, it launchs a URL to Coldfusion, that queries the database and opens the PDF link. This all works but we also want to have the open PDF goto a section or bookmark within the PDF. We currently have JavaScripts within the PDF links that do that but only if the PDF is in the file system. We're using the app.openDoc to get a reference to the opened PDF. But when opening the PDF from the database we pass the control to Coldfusion using app.launchURL or app.getURL. These do not pass back a reference to the opened PDF and the JavaScripts fails.
    I'm looking for different methods or ideas.
    Is there another way to do this, I'm new to acrobat JavaScripting?
    Thanks, Rob

    I tried tapping and holding the attachment icon, it just shows "Open / Bookmark/ Copy"...
    Also i tried opening the attachement first and then tapping on it, it just shows "open in Safari"
    Is there any settings to be done to add the options of Opening in Adobe Reader/or any other Docu Sign app . the exhibition booth systems one would work i think
    Appreciate if someone could help

  • How to know corresponding info object for R/3 field and viceversa

    Hi....
    How to know corresponding object for a filed in r/3 data source and viceversa..While defining transformations.
    We can't do mapping of all objects to fields with the definition......!!!
    In 'rsosfieldmap'' what information we should give to know the proper tranformation...?
    thank u.....

    Hi,
    There are two ways to know the corresponding info objects in R/3 fields:
    1)  goto se11 t-code, enter RSOSFIELDMAP and enter display button. in the next screen click contents and give the field name or info object name as per your requirement, and excute.
    2)  first go through the field description in r/3 and identify the similar description in BI. For your easy understanding use excel sheet , in that you can copy the data source fields and target info objects ( master data or transaction data ). then it will be easy to identify the similar description.
    Thank you.

  • Vendor as customer and viceversa

    Hello,
    My scenario is that i have several vendors that are customers at the same time. And viceversa, several customers that are vendors too. I have made the customizing, into the customer I have put the vendor nr and the check 'clearing with vendor', and into the vendor the customer nr and the check 'clearing...'. I have anyway two problems:
    1) When i execute f-28 (incoming payments) or f-53 (outgoing payments), i see the items of the customer/vendor both. No problem.  But i can't clear different amounts. I have:
    Customer: +232 EUR
    Vendor:    -136 EUR
    And i can't clear these.
    2) My second problem comes when i execute F110 (automatic payments). At the end of the process i see the payment to make to vendor and one exeption for the customer incoming payment.
    > Bank details are being checked                                       
    >   System reads house banks and checks if they are allowed            
    > Our bank DUMMY is being checked                                      
    > Bank different from the specified bank AA in master record or items  
    >   House bank is selected ...                                         
    > No permitted payment method exists                                   
    Information re. vendor 1 / customer 2 / paying company code 01 ...
    ... payment not possible because of reported error            
    Thank you all the experts.

    In the example you have a payment will need to be received sent - therefore a payment method needs to be applied to the customer and vendor master.
    If you want to offset the customer invoice against the vendor invoice - you can clear it via F-32, and then add other items "K" for account group and then the Vendor number.

  • Browser is not allowing sign in to excite web page. it says my settings are configured to disable cookies and/or javascript. please help

    i just got firefox 4.0, and i tried to simply sign in to myexcite.com, but instead the message "the browser you're using is not allowing you to sign in to Excite. Right now , your browser's settings are configured to disable cookies and/or javascript..."
    Please Help. I am new to Firefox 4.0

    First, create a specific [[Managing profiles|profile]] for Firefox 4.0b8 to prevent interferences between current (Firefox 3.6) and beta (Firefox 4.0b8) versions.
    Then, see [[Cannot log in to websites]].

  • After having updated Ipad2 to IOS7 I can't change Video to Photo and viceversa on photocamera. Solutions?

    After having updated Ipad2 to IOS7 I can't change Video to Photo and viceversa on photocamera. Solutions?

    Have you tried swiping up or down on the screen in the photos app? When you swipe up or down, that cycles through the Photo, Video and Square modes in the app. The current mode appears in yellow type.
    The screen on the iPad in photos App is going to look different that what you see if you click on the link that was posted for you above - that link shows what the screen will look like on the iPhone, but they are similar.

  • Read and write(control should act as indicator and viceversa)

    control(input) should act as indicator(output) and viceversa for a string transmission.is it possible
    kudos welcome
    Solved!
    Go to Solution.

    Yes you can.  But property nodes are much slower than local variables.  For simple programs, you won't notice the difference.  But sooner or later, you will encounter a case where too many property nodes will noticeably slow down the code.  It is considered bad programming style to use property nodes instead of local variables.  Property Nodes work through the UI thread.  Locals do not.  So locals present a lot less overhead. 
    It is best to not get into a bad habit from the start.  Use local variables instead of property nodes.
    I do use local variables and think it is ok but there are the people on here that think they are the worst thing ever invented. Also it is not bad to show a couple of different way to do things so the OP can learn different ways to do things. Property nodes are something that you will inevitably have to learn if the OP wants to do real programming.
    Tim
    Johnson Controls
    Holland Michigan

  • BCD to decimal and viceversa

    Hi,
    Am working on conversion of decimal to BCD (Binary coded decimal) and viceversa. I require BCD for calling Cobol from Java using JNI.
    Can anybody help me out in giving a pointer or an algorithm for doing the same.
    I Googled on the web for any info on BCD conversion, but all in vain. Even Java Forums here in Sun also donot have any info on the same.
    Please help me out.
    TIA,
    Prashanth Babu.

    You'll have to adjust this to do put the output where you want. Surely not the only (and maybe not elegant):
       /** Write specified string into stream as two Binary-Coded Decimal (BCD)
        *     digits.
       private static void writeTwoBCDDigits(DataOutputStream stream,
                                             String           twoDigits)
              throws IOException
          // Convert two digits to Binary-Coded Decimal (BCD).
          // The "write(int)" function writes a numeric value in binary to the
          //    stream.
          // If the twoDigits string is parsed as a hexadecimal integer, then
          //    writing the equivalent decimal integer using "write(int)" will
          //    generate the correct BCD numbers.
          // For example, if twoDigits is "54", parsing this as the hexadecimal
          //    integer 54 results in twoBCDDigits as the decimal integer 84.
          //    Then, "write(84)" will write the correct bits to the stream:
          //    "0101 0100" (space not included).
          //    "0101" = BCD '5' and "0100" = BCD '4'.
          int twoBCDDigits = Integer.parseInt(twoDigits, 16);
          // Write out the numeric value of twoBCDDigits in one byte.
          stream.write(twoBCDDigits);
       }

  • Mail suddenly marks as spam what is not and viceversa. It has worked perfectly until a few days ago. How can I restore the old junk "learnt" list? Where is it to be found?

    Mail suddenly marks as spam what is not and viceversa.
    It has worked perfectly until a few days ago. How can I restore the old junk "learnt" list, since it is marking as SPAM senders who have been my correspondants for years?? Where is the old junk pref file to be found?

    Why start a new and very similar thread to your other one which you have not responded to (have you read the replies?)
    I suggest that no response is made to this duplicate thread. 

  • Getting rid of the row_mouse_over and row_mouse_out javascript?

    Seems the row_mouse_over and row_mouse_out Javascript functions get added automatically to report regions, to support formatting of background color, hovering, etc.
    However, this just bloats up the page size (in addition to the size of the functions themselves, calls to these functions get repeated for every table row).
    Is there any way to get rid of them?
    (I believe I read somewhere that they were hard-wired into the standard templates, and that you have to create a new report template, which must be with specific columns (as opposed to generic columns). If true, this is something of a bummer, as I'd have to create a different template for every report region.... :-(

    Hello,
    >> Seems the row_mouse_over and row_mouse_out Javascript functions get added automatically to report regions, to support formatting of background color, hovering, etc.
    I believe this is done using the #HIGHLIGHT_ROW# substitution string, in the “Before Each Row” section of your report template. You can try and remove it. In version 3.1 you can define your own #REPORT_ATTRIBUTES# substitution string, using the “Report Attributes Substitution” field, in the report “Layout and Pagination” section.
    I didn’t tried it myself, so please report back if you will be successful.
    Regards,
    Arie.

  • Firefox and click javascript function on h:commandLink

    I was wondering if you can help me with a problem i'm having with a h:commandLink tag. What I am trying to do is give the user a choice of executing the action or not by using the confirm() and click() javascript functions:
    <h:commandLink id="runNowLink" styleClass="tableFooterText" value="#{ViewResources.RunNow}" action="#{Schedule.runNow}" onmouseup="if(confirm('#{ViewResources.RunNowConfirm}')) this.click()"/>
    This works in IE, a dialog box with "ok" and "cancel" appears and depending on which option the user selects, the link is "clicked" or not. However, this does not work in firefox as the browser just goes through with the action regardless of the option selected. Can someone please help?

    probably set the property of <h:commandLink type="submit" /> or <h:commandLink immediate="true" />

  • Alert, confirm and prompt javascript functions died with ios 7

    Alert, confirm and prompt javascript functions died with ios7.  Will it be fixed? It breaks websites.

    Hi..
    JavaScript is no longer available to switch on or off in Settings > Safari.
    So apparently that function has died with iOS 7.
    message edited by:  cs

  • Send information from Oracle DB - PI - NW 7.0 BI and viceversa

    Hello,
    I need to send information from Oracle DB to SAP NW 7.0 BI passing through a SAP PI and viceversa.
    Ho can I do that?
    I need help
    Best Regards...
    Pablo Mortera.

    As the sender is ORacle you can use a sender adapter which is JDBC in XI.
    As the receiver is BI system, try to use either Proxy or RFC or Idoc as a receiver adapter.
    Regards
    Krish

  • Celsius to Farenheit and viceversa

    Hello everyone, I hope someone can help me with a project I am working on.
    I need to do a simple VI that converts from degrees C to degrees F and viceversa. In the front panel, the user should be able to convert from one to the other. For example, if there are 2 thermometers and the user slides the Celsius degrees down to 0, the other thermometer should move to 32 degrees. However, the user should ALSO be able to go the opposite direction while the VI is running. In other words, the user should be able to change the temperature in EITHER thermometer and the OTHER should change accordingly. I am only able to go ONE direction because I think I should be able to have some sort of control that also works as an indicator. Please let me know if there is a way to do this!!! THANKS.

    You can also use "units" for each control (degF and degC, resp.), no more conversion math needed.
    Message Edited by altenbach on 02-18-2007 07:51 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    DualT.vi ‏14 KB
    DualT.png ‏6 KB

  • Sending and parse javascript object variable to java variable

    can anyone help me how to send and parse javascript object variable from client to java variable on servlet. Here is what i mention about:
    suppose i have object variable var_js with it's properties:
    <script>
    var var_js = {
    id: 'var_js1',
    name: 'this is var javascript',
    allow_value_type: ['int', 'string', 'object']
    </script>
    /* after processing javascript object to java var, that i hope you guys may help me, it's java var (var_java) become something like*/
    var_java.id = "var_js1";
    var_java.name = "this is var javascript";
    var_java.allow_value_type = {"int", "string", "object"}

    You could have this html page:
    <html>
    <script>
    var var_js = {
    id: 'var_js1',
    name: 'this is var javascript',
    allow_value_type: ['int', 'string', 'object']
    function send()
    document.getElementById("id").value = var_js.id;
    document.getElementById("name").value =var_js.name;
    document.getElementById("allow_value_type").value =var_js.allow_value_type;
    document.form.submit();
    </script>
    <form name="myForm" action="http://localhost:8080/servlet/myServlet" method="post" >
    <input id="id" type="hidden" value="">
    <input id="name" type="hidden" value="">
    <input id="allow_value_type" type="hidden" value="">
    <input id="cmdGo" type="button" value="Button" onClick="send()">
    </form>
    </html>
    Then have a servlet like this:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class myServlet extends HttpServlet {
    public void doPost( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String allowed_value_type = request.getParameter("allowed_value_type");
    Var_java var_java = new Var_java(id,name,allowed_value_type);
    //and have you java object
    class Var_java
    String id;
    String name;
    String allowed_value_type;
    public var_java(String id,String name,String allowed_value_type)
    this.id=id;
    this.name=name;
    this.allowed_value_type=allowed_value_type;
    well...something like that i think.
    Hope it helps.

Maybe you are looking for