Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(27)  |  Call(22)  |  Derive(0)  |  Import(5)
Transforms a timestamp into a two digits Decimal.

Arg:
    value: timestamps representation - float or str.
    If None, uses time.time()

    precision: number of digits to keep. defaults to 2.

Return:
    A Decimal two-digits instance.

        def round_time(value=None, precision=2):
    """Transforms a timestamp into a two digits Decimal.

    Arg:
        value: timestamps representation - float or str.
        If None, uses time.time()

        precision: number of digits to keep. defaults to 2.

    Return:
        A Decimal two-digits instance.
    """
    if value is None:
        value = time.time()
    if not isinstance(value, str):
        value = str(value)
    try:
        digits = '0' * precision
        return Decimal(value).quantize(Decimal('1.' + digits))
    except InvalidOperation:
        raise ValueError(value)
        


src/a/p/appsync-HEAD/appsync/storage/sql.py   appsync(Download)
 
from mozsvc.exceptions import BackendError
from mozsvc.util import round_time, maybe_resolve_name
 
from appsync.cache import Cache, CacheError
 
        # using hundredth of seconds
        since = int(round_time(since) * 100)
 
        # if since is after last_modified we just return []
 
        # XXX dumb: serialize/unserialize round trip for nothing
        return [(round_time(app.last_modified / 100.),
                 json.loads(app.data)) for app in apps]
 
            self._execute(queries.REMOVE_DEL, user=user, collection=collection)
 
        now = int(round_time() * 100)
 
        # let's see if we have an uuid
            return None
        # last modified is a timestamp * 100
        return round_time(res.last_modified / 100.)
 
    def verify(self, assertion, audience):

src/a/p/appsync-HEAD/appsync/storage/sauropod.py   appsync(Download)
from zope.interface import implements
 
from mozsvc.util import round_time
 
import vep.utils
            raise CollectionDeletedError(meta.get("client_id", ""),
                                         meta.get("reason", ""))
        return round_time(meta.get("last_modified", 0))
 
    @convert_sauropod_errors
        meta_data["etags"] = {}
        meta_data["uuid"] = None
        meta_data["last_modified"] = round_time()
        self._set_cached_metadata(s, user, collection, meta_data, meta_etag)
 
    def get_applications(self, user, collection, since, token):
        """Get all applications that have been modified later than 'since'."""
        s = self._resume_session(token)
        since = round_time(since)
        updates = []
            raise CollectionDeletedError(meta.get("client_id", ""),
                                         meta.get("reason", ""))
        last_modified = round_time(meta.get("last_modified", 0))
        if last_modified < since:
            return updates

src/a/p/appsync-HEAD/appsync/views.py   appsync(Download)
 
from cornice import Service
from mozsvc.util import round_time
from webob import exc
 
    try:
        since = request.GET.get('since', '0')
        since = round_time(since)
    except TypeError:
        raise bad_request(INVALID_SINCE_VALUE)
    """
    user, collection, dbtoken = check_auth(request)
    server_time = round_time()
    storage = get_storage(request)
 
 
    elif 'lastget' in request.params:
        last_get = round_time(float(request.params['lastget']))
        last_modified = storage.get_last_modified(user, collection,
                                                  token=dbtoken)

src/m/o/mozsvc-0.7/mozsvc/tests/test_util.py   mozsvc(Download)
import os.path
 
from mozsvc.util import (round_time, resolve_name, maybe_resolve_name,
                         dnslookup)
 
    def test_round_time(self):
 
        # returns a two-digits decimal of the current time
        res = round_time()
        self.assertEqual(len(str(res).split('.')[-1]), 2)
 
        # can take a timestamp
        res = round_time(129084.198271987)
 
        # can take a str timestamp
        res = round_time('129084.198271987')
        self.assertEqual(str(res), '129084.20')
 
 
        # changing the precision
        res = round_time(129084.198271987, precision=3)
        self.assertEqual(str(res), '129084.198')
 

src/m/o/mozservices-HEAD/mozsvc/tests/test_util.py   mozservices(Download)
import os.path
 
from mozsvc.util import (round_time, resolve_name, maybe_resolve_name,
                         dnslookup)
 
    def test_round_time(self):
 
        # returns a two-digits decimal of the current time
        res = round_time()
        self.assertEqual(len(str(res).split('.')[-1]), 2)
 
        # can take a timestamp
        res = round_time(129084.198271987)
 
        # can take a str timestamp
        res = round_time('129084.198271987')
        self.assertEqual(str(res), '129084.20')
 
 
        # changing the precision
        res = round_time(129084.198271987, precision=3)
        self.assertEqual(str(res), '129084.198')