How to use jdatetime - 10 common examples

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 slashmili / django-jalali / jalali_test / foo / tests.py View on Github external
def setUp(self):
        self.date_string = "1380-08-02"
        self.datetime = jdatetime.datetime(1380, 8, 2, 12, 12, 12)
        self.bar_time = BarTime(name="foo time", datetime=self.datetime)
        self.bar_time.save()
github slashmili / django-jalali / jalali_test_2_0 / foo / tests.py View on Github external
def test_lookup_date_with_no_tz(self):
        jdt1 = jdatetime.datetime(1392, 3, 12, 10, 22, 23, 240000)
        m1 = BarTime.objects.create(name="with timezone", datetime=jdt1)
        k = BarTime.objects.filter(datetime=jdt1)
        self.assertEqual(k[0].datetime.strftime('%z'), '')
github slashmili / django-jalali / jalali_test_2_0 / foo / tests.py View on Github external
def setUp(self):
        self.request_factory = RequestFactory()
        self.today = jdatetime.date.today()
        self.tomorrow = self.today + jdatetime.timedelta(days=1)
        self.one_week_ago = self.today - jdatetime.timedelta(days=7)
        if self.today.month == 12:
            self.next_month = self.today.replace(year=self.today.year + 1, month=1, day=1)
        else:
            self.next_month = self.today.replace(month=self.today.month + 1, day=1)
        self.next_year = self.today.replace(year=self.today.year + 1, month=1, day=1)

        #Bars
        self.mybartime = BarTime.objects.create(name="foo", datetime=self.today)
github slashmili / django-jalali / jalali_test / foo / tests.py View on Github external
def setUp(self):
        self.request_factory = RequestFactory()
        self.today = jdatetime.date.today()
        self.tomorrow = self.today + jdatetime.timedelta(days=1)
        self.one_week_ago = self.today - jdatetime.timedelta(days=7)
        if self.today.month == 12:
            self.next_month = self.today.replace(year=self.today.year + 1, month=1, day=1)
        else:
            self.next_month = self.today.replace(month=self.today.month + 1, day=1)
        self.next_year = self.today.replace(year=self.today.year + 1, month=1, day=1)

        # Bars
        self.mybartime = BarTime.objects.create(name="foo", datetime=self.today)
github slashmili / django-jalali / jalali_test / foo / tests.py View on Github external
def setUp(self):
        self.request_factory = RequestFactory()
        self.today = jdatetime.date.today()
        self.tomorrow = self.today + jdatetime.timedelta(days=1)
        self.one_week_ago = self.today - jdatetime.timedelta(days=7)
        if self.today.month == 12:
            self.next_month = self.today.replace(year=self.today.year + 1, month=1, day=1)
        else:
            self.next_month = self.today.replace(month=self.today.month + 1, day=1)
        self.next_year = self.today.replace(year=self.today.year + 1, month=1, day=1)

        # Bars
        self.mybartime = BarTime.objects.create(name="foo", datetime=self.today)
github slashmili / django-jalali / jalali_test_2_0 / foo / tests.py View on Github external
def setUp(self):
        self.request_factory = RequestFactory()
        self.today = jdatetime.date.today()
        self.tomorrow = self.today + jdatetime.timedelta(days=1)
        self.one_week_ago = self.today - jdatetime.timedelta(days=7)
        if self.today.month == 12:
            self.next_month = self.today.replace(year=self.today.year + 1, month=1, day=1)
        else:
            self.next_month = self.today.replace(month=self.today.month + 1, day=1)
        self.next_year = self.today.replace(year=self.today.year + 1, month=1, day=1)

        #Bars
        self.mybartime = BarTime.objects.create(name="foo", datetime=self.today)
github slashmili / django-jalali / django_jalali / db / models.py View on Github external
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))
            raise exceptions.ValidationError(msg)
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
datetime_obj.minute, datetime_obj.second,
                        datetime_obj.microsecond, datetime_obj.tzinfo)
                else:
                    return jdatetime.datetime.fromgregorian(
                        datetime=datetime_obj)
            except ValueError:
                raise exceptions.ValidationError(
                    self.error_messages['invalid'])
        if isinstance(datetime_obj, datetime.date):
            try:
                if datetime_obj.year < 1700:
                    return jdatetime.datetime(datetime_obj.year,
                                              datetime_obj.month,
                                              datetime_obj.day)
                else:
                    return jdatetime.datetime.fromgregorian(date=datetime_obj)
            except ValueError:
                raise exceptions.ValidationError(
                    self.error_messages['invalid'])

        # Attempt to parse a datetime:
        datetime_obj = smart_str(datetime_obj)
        if not datetime_obj:
            return None
        # split usecs, because they are not recognized by strptime.
        if '.' in datetime_obj:
            try:
                datetime_obj, usecs = datetime_obj.split('.')
                if '+' in usecs:
                    usecs, tz = usecs.split('+')
                usecs = int(usecs)
            except ValueError:
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)