How to use the jdatetime.date.fromgregorian function in jdatetime

To help you get started, we’ve selected a few jdatetime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github irLinja / PhotoSort / photosort.py View on Github external
except IOError, Argument:
        print colored('%s: %s' % (file, Argument.strerror), 'red')
        continue
    else:
        tags = exifread.process_file(f)
        if not len(tags):
            print colored('%s: %s' % (file, 'No EXIF data found'), 'red')
            continue
        else:
            tag = 'EXIF DateTimeOriginal'
            if tag not in tags.keys():
                print colored('%s: %s' % (file, 'Tag not found in EXIF'), 'red')
                continue

            rawdate = str(tags[tag]).split()[0].split(':')
            jdate = jdatetime.date.fromgregorian(day=int(rawdate[2]),month=int(rawdate[1]),year=int(rawdate[0]))
            dirname = "%s/%s/%s/%s" % (args.out, jdate.year, '%.2d' % jdate.month, '%.2d' % jdate.day)
            if os.path.isfile('%s/%s' % (dirname,file.split('/')[-1])):
                print colored(('%s: %s' % (file, jdate)).ljust(80, '.') + '[ DU ]', 'red')
                continue

            if not os.access(file, os.R_OK):
                print colored(('%s: %s' % (file, jdate)).ljust(80, '.') + '[ NR ]', 'red')
                continue

            if not args.noact:
                os.system('mkdir -p %s' % (dirname))
                os.system('cp "%s" "%s"' % (file, dirname))

            print colored(('%s: %s' % (file, jdate)).ljust(80, '.') + '[ OK ]', 'cyan')
github slashmili / django-jalali / django_jalali / db / models.py View on Github external
def parse_date(self, date_obj):
        "Take a datetime object and convert it to jalali date"

        if isinstance(date_obj, datetime.datetime):
            return jdatetime.date.fromgregorian(date=date_obj.date())
        if isinstance(date_obj, datetime.date):
            return jdatetime.date.fromgregorian(date=date_obj)

        if not ansi_date_re.search(date_obj):
            raise exceptions.ValidationError(self.error_messages['invalid'])
        # Now that we have the date string in YYYY-MM-DD format, check to make
        # sure it's a valid date.
        # We could use time.strptime here and catch errors, but datetime.date
        # produces much friendlier error messages.
        year, month, day = map(int, date_obj.split('-'))
        try:
            if year > 1500:
                return jdatetime.date.fromgregorian(
                    date=datetime.date(year, month, day))
            else:
                return jdatetime.date(year, month, day)
github slashmili / django-jalali / django_jalali / db / models.py View on Github external
def parse_date(self, date_obj):
        "Take a datetime object and convert it to jalali date"

        if isinstance(date_obj, datetime.datetime):
            return jdatetime.date.fromgregorian(date=date_obj.date())
        if isinstance(date_obj, datetime.date):
            return jdatetime.date.fromgregorian(date=date_obj)

        if not ansi_date_re.search(date_obj):
            raise exceptions.ValidationError(self.error_messages['invalid'])
        # Now that we have the date string in YYYY-MM-DD format, check to make
        # sure it's a valid date.
        # We could use time.strptime here and catch errors, but datetime.date
        # produces much friendlier error messages.
        year, month, day = map(int, date_obj.split('-'))
        try:
            if year > 1500:
                return jdatetime.date.fromgregorian(
                    date=datetime.date(year, month, day))
            else:
                return jdatetime.date(year, month, day)
        except ValueError as e:
            msg = self.error_messages['invalid_date'] % _(str(e))
github slashmili / django-jalali / django_jalali / templatetags / jformat.py View on Github external
def jformat(value, arg=None):
    """Formats a date or time according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = "%c"
    try:
        if isinstance(value, datetime):
            value = jdatetime.datetime.fromgregorian(datetime=value)
        elif isinstance(value, date):
            value = jdatetime.date.fromgregorian(date=value)
        return value.strftime(arg)
    except AttributeError:
        return ''
github mehotkhan / persian-twitter-day / tw / views.py View on Github external
lambda d: jdatetime.datetime.fromgregorian(datetime=d).strftime(
                '%m/%d - %H:%m ') if isinstance(d, datetime.datetime) else jdatetime.date.fromgregorian(
                date=d).strftime(
                '%a %m/%d'),
            self.date_list[:-1])
github a-roomana / django-jalali-date / jalali_date / __init__.py View on Github external
def date2jalali(g_date):
    return jdatetime.date.fromgregorian(date=g_date) if g_date else None