Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help for convert from PHP
Message
 
À
21/11/2011 07:39:22
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01529341
Message ID:
01529348
Vues:
28
Try this:
 *    Jalali, a Gregorian to Jalali and inverse date convertor
 * Copyright (C) 2001, 2002  Roozbeh Pournader <roozbeh@farsiweb.info>
 * Copyright (C) 2001, 2002  Mohammad Toossi <mohammad@bamdad.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You can receive a copy of GNU Lesser General Public License at the
 * World Wide Web address <http://www.gnu.org/licenses/lgpl.html>.
 *
 * For licensing issues, contact The FarsiWeb Project Group,
 * Computing Center, Sharif University of Technology,
 * PO Box 11365-8515, Tehran, Iran, or contact us the
 * email address <FWPG@sharif.edu>.
 */

* Changes:
 * 
 * 2002-Feb-19:
 *    Added PHP header and tailer
 * 2002-Jan-28:
 *    First LGPL release
 */
 
 
 
 

DIMENSION g_days_in_month[12], j_days_in_month[12]
g_days_in_month[ 1] = 31
g_days_in_month[ 2] = 28
g_days_in_month[ 3] = 31
g_days_in_month[ 4] = 30
g_days_in_month[ 5] = 31
g_days_in_month[ 6] = 30
g_days_in_month[ 7] = 31
g_days_in_month[ 8] = 31
g_days_in_month[ 9] = 30
g_days_in_month[10] = 31
g_days_in_month[11] = 30
g_days_in_month[12] = 31

j_days_in_month[ 1] = 31
j_days_in_month[ 2] = 31
j_days_in_month[ 3] = 31
j_days_in_month[ 4] = 31
j_days_in_month[ 5] = 31
j_days_in_month[ 6] = 31
j_days_in_month[ 7] = 30
j_days_in_month[ 8] = 30
j_days_in_month[ 9] = 30
j_days_in_month[10] = 30
j_days_in_month[11] = 30
j_days_in_month[12] = 29

j_month_name    = ["Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"]


 ooo = gregorian_to_jalali(2012, 1, 21)
 ? ooo.Year, ooo.Month, ooo.Day



function div(a, b)
return INT(a / b)
  
function gregorian_to_jalali(g_y, g_m, g_d)
   
   gy = g_y-1600
   gm = g_m-1
   gd = g_d-1

   g_day_no = 365*gy+div(gy+3,4)-div(gy+99,100)+div(gy+399,400);

   for i=1 TO gm
      g_day_no = g_day_no + g_days_in_month[i]
   NEXT
   
   if (gm > 1 AND ((gy%4==0 AND gy%100!=0) OR (gy%400==0)))
      g_day_no = g_day_no + 1
   ENDIF
   g_day_no = g_day_no + gd
 
   j_day_no = g_day_no-79
 
   j_np = div(j_day_no, 12053)
   j_day_no = j_day_no % 12053
 
   jy = 979+33*j_np+4*div(j_day_no,1461)

   j_day_no = j_day_no % 1461
 
   if (j_day_no >= 366)
      jy = jy + div(j_day_no-1, 365)
      j_day_no = (j_day_no-1)%365
   ENDIF
 
   for i = 1 TO 11
      IF j_day_no >= j_days_in_month[i]
         j_day_no = j_day_no - j_days_in_month[i]
      ELSE
         EXIT
      ENDIF
   NEXT
   jm = i
   jd = j_day_no+1

   oReturn = CREATEOBJECT([EMPTY])
   ADDPROPERTY(oReturn,[Year], jy)
   ADDPROPERTY(oReturn,[Month], jm)
   ADDPROPERTY(oReturn,[Day], jd)
RETURN oReturn
Not sure at all if this coverts dates right :-)
I tested just two dates in here http://i.syavash.com/datec/ and the function returns the same values as the site.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform