volume value is based on the pub date year
    pub_date is a python time object
173901
def calculate_journal_volume(pub_date, year):
    
    try:
        volume = str(pub_date.tm_year - year + 1)
    except TypeError:
        volume = None
    except AttributeError:
        volume = None
    return volume
321617
def convert_to_database_compatible_value(value):
    
    if pd.isnull(value):
        return None
    if isinstance(value, pd.Timestamp):
        return value.to_pydatetime()
    try:
        return value.item()
    except AttributeError:
        return value
1327874
def is_within_publication_dates(obj, timestamp=None):
        
        if timestamp is None:
            timestamp = timezone.now()
        start_date_ok = not obj.publication_date \
            or obj.publication_date <= timestamp
        end_date_ok = not obj.publication_end_date \
            or obj.publication_end_date > timestamp
        return start_date_ok and end_date_ok
901160
def value(self, value, *args, **kwargs):
        
        from datetime import datetime
        value = self.obj.value(value, *args, **kwargs)
        try:
            rv = datetime.strptime(value, self.format)
        except ValueError as _:  # noqa
            rv = None
        return rv
503758
def expected_bar_value(asset_id, date, colname):
    
    from_asset = asset_id * 100000
    from_colname = OHLCV.index(colname) * 1000
    from_date = (date - PSEUDO_EPOCH).days
    return from_asset + from_colname + from_date
442492
def pythonvaluetotime(time_val):
    ""
    if time_val is None:
        return None
    elif isinstance(time_val, numeric):
        return str(long(time_val * 1000.0))
    elif isinstance(time_val, date):
        dtlist = [time_val.year, time_val.month, time_val.day]
        if isinstance(time_val, datetime.datetime):
            dtlist += [time_val.hour, time_val.minute, time_val.second]
        else:
            dtlist += [0, 0, 0]
        return long(calendar.timegm(dtlist) * 1000.0)
    elif (isinstance(time_val, sequence)
                    and len(time_val) == 2):
        if all(isinstance(x, numeric) 
               for x in time_val):
            return ",".join(pythonvaluetotime(x) 
                            for x in time_val)
        elif all(isinstance(x, date) 
               for x in time_val):
            return ",".join(pythonvaluetotime(x) 
                            for x in time_val)
    raise ValueError(repr(time_val))
1137152
def dbStore(self, typ, py_value):
        
        if isinstance(py_value, datetime.datetime):
            return time.mktime(py_value.timetuple())
        else:
            return super(UTC_TimestampColumn, self).dbStore(typ, py_value)
1271968
def timetopythonvalue(time_val):
    ""
    if isinstance(time_val, sequence):
        return map(timetopythonvalue, time_val)
    elif isinstance(time_val, numeric):
        return datetime.datetime(*(time.gmtime(time_val))[:6])
    elif isinstance(time_val, numeric):
        values = []
        try:
            values = map(long, time_val.split(","))
        except:
            pass
        if values:
            return map(timetopythonvalue, values)
    raise ValueError(repr(time_val))
749476
def creation_time(self):
    """"""
    timestamp = self._bde_volume.get_creation_time_as_integer()
    return dfdatetime_filetime.Filetime(timestamp=timestamp)
239107
def datetime2gtd(time: Union[str, datetime.datetime, np.datetime64],
                 glon: Union[float, List[float], np.ndarray] = np.nan) -> Tuple[int, float, float]:
    
# %%
    T = np.atleast_1d(time)
    glon = np.asarray(glon)
    doy = np.empty_like(T, int)
    utsec = np.empty_like(T, float)
    stl = np.empty((T.size, *glon.shape))

    for i, t in enumerate(T):
        if isinstance(t, str):
            t = parse(t)
        elif isinstance(t, np.datetime64):
            t = t.astype(datetime.datetime)
        elif isinstance(t, (datetime.datetime, datetime.date)):
            pass
        else:
            raise TypeError('unknown time datatype {}'.format(type(t)))
# %% Day of year
        doy[i] = int(t.strftime('%j'))
# %% seconds since utc midnight
        utsec[i] = datetime2utsec(t)

        stl[i, ...] = utsec[i] / 3600. + glon / 15.

    return doy, utsec, stl
406485
def absdatetime(ts, default=None):
    """"""
    if ts is None:
        ts = default
    if isinstance(ts, dict):
        ts = timedelta(**ts)
    if isinstance(ts, timedelta):
        ts = now() + ts
    if isinstance(ts, datetime):
        return ts
    return None
1167311
def pub_date(soup):
    
    pub_date = first(raw_parser.pub_date(soup, date_type="pub"))
    if pub_date is None:
        pub_date = first(raw_parser.pub_date(soup, date_type="publication"))
    if pub_date is None:
        return None
    (day, month, year) = ymd(pub_date)
    return date_struct(year, month, day)
295063
def _http_date(_date_str: str) -> Optional[datetime.datetime]:
        
        if _date_str is not None:
            timetuple = parsedate(_date_str)
            if timetuple is not None:
                return datetime.datetime(*timetuple[:6],
                                         tzinfo=datetime.timezone.utc)
        return None
233633
def from_bs_date(cls, year, month, day):
        
        return NepDate(year, month, day).update()
486779
async def setvolume(self, value):
        

        self.logger.debug("volume command")

        if self.state != 'ready':
            return

        logger.debug("Volume command received")

        if value == '+':
            if self.volume < 100:
                self.statuslog.debug("Volume up")
                self.volume = (10 * (self.volume // 10)) + 10
                self.volumelog.info(str(self.volume))
                try:
                    self.streamer.volume = self.volume / 100
                except AttributeError:
                    pass
            else:
                self.statuslog.warning("Already at maximum volume")

        elif value == '-':
            if self.volume > 0:
                self.statuslog.debug("Volume down")
                self.volume = (10 * ((self.volume + 9) // 10)) - 10
                self.volumelog.info(str(self.volume))
                try:
                    self.streamer.volume = self.volume / 100
                except AttributeError:
                    pass
            else:
                self.statuslog.warning("Already at minimum volume")

        else:
            try:
                value = int(value)
            except ValueError:
                self.statuslog.error("Volume argument must be +, -, or a %")
            else:
                if 0 <= value <= 200:
                    self.statuslog.debug("Setting volume")
                    self.volume = value
                    self.volumelog.info(str(self.volume))
                    try:
                        self.streamer.volume = self.volume / 100
                    except AttributeError:
                        pass
                else:
                    self.statuslog.error("Volume must be between 0 and 200")

        self.write_volume()
30790
def set_pub_year_month_day(self, xml_dict):
        
        key_path = ['PubmedArticleSet', 'PubmedArticle', 'MedlineCitation',
                    'Article', 'Journal', 'JournalIssue', 'PubDate']
        pubdate_xml = reduce(dict.get, key_path, xml_dict)

        if isinstance(pubdate_xml, dict):
            self.year = pubdate_xml.get('Year')
            month_short = pubdate_xml.get('Month')
            self.day = pubdate_xml.get('Day')

            try:
                self.month = datetime.datetime.strptime(
                    month_short, "%b").month
            except (ValueError, TypeError):
                self.month = ''

        else:
            self.year = ''
            self.month = ''
            self.day = ''
573283
def strptime(time_str, time_format):
        
        try:
            datetime_obj = datetime.strptime(time_str, time_format)
            return datetime_obj
        except ValueError as ex:
            raise ValueError(ex)