How to use the jdatetime.timedelta 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 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 / admin / filters.py View on Github external
def __init__(self, field, request, params, model, model_admin, field_path):
        self.field_generic = '%s__' % field_path
        self.date_params = {k: v for k, v in params.items()
                            if k.startswith(self.field_generic)}

        now = jdatetime.datetime.fromgregorian(datetime=timezone.now())
        if timezone.is_aware(now):
            now = timezone.localtime(now)

        if isinstance(field, models.jDateTimeField):
            today = now.replace(hour=0, minute=0, second=0, microsecond=0)
        else:
            today = now.date()

        tomorrow = today + jdatetime.timedelta(days=1)

        if today.month == 12:
            next_month = today.replace(year=today.year + 1, month=1, day=1)
        else:
            next_month = today.replace(month=today.month + 1, day=1)
        next_year = today.replace(year=today.year + 1, month=1, day=1)

        self.lookup_kwarg_since = '%s__gte' % field_path
        self.lookup_kwarg_until = '%s__lt' % field_path
        self.links = (
            (_('Any date'), {}),
            (_('Today'), {
                self.lookup_kwarg_since: today.strftime('%Y-%m-%d %H:%M:%S'),
                self.lookup_kwarg_until: tomorrow.strftime('%Y-%m-%d %H:%M:%S'),
            }),
            (_('Past 7 days'), {
github slashmili / django-jalali / django_jalali / admin / filterspecs.py View on Github external
def __init__(self, f, request, params, model, model_admin,
                 field_path=None):
        super(jDateFieldFilterSpec, self).__init__(
            f, request, params, model, model_admin, field_path=field_path
        )
        self.field_generic = '%s__' % self.field_path

        self.date_params = dict([(k, v) for k, v in params.items() if k.startswith(self.field_generic)])

        today = jdatetime.date.today()
        one_week_ago = today - jdatetime.timedelta(days=7)
        # today_str = isinstance(self.field, jmodels.DateTimeField) \
        #            and today.strftime('%Y-%m-%d 23:59:59') \
        #            or today.strftime('%Y-%m-%d')
        today_str = today.strftime('%Y-%m-%d')

        last_day_this_month = 29
        if today.month == 12 and today.isleap():
            last_day_this_month = 30
        else:
            last_day_this_month = jdatetime.j_days_in_month[today.month-1]

        last_day_this_year = 29
        if today.isleap():
            last_day_this_year = 30

        self.links = (