# Path: casacore/quanta/quantity.py
# def quantity(*args):
#     """Create a quantity. This can be from a scalar or vector.
# 
#     Example::
# 
#       q1 = quantity(1.0, "km/s")
#       q2 = quantity("1km/s")
#       q1 = quantity([1.0,2.0], "km/s")
# 
#     """
#     if len(args) == 1:
#         if isinstance(args[0], string_types):
#             # use copy constructor to create quantity from string
#             return Quantity(from_string(args[0]))
#         elif isinstance(args[0], dict):
#             if hasattr(args[0]["value"], "__len__"):
#                 return QuantVec(from_dict_v(args[0]))
#             else:
#                 return Quantity(from_dict(args[0]))
#         elif isinstance(args[0], Quantity) or isinstance(args[0], QuantVec):
#             return args[0]
#         else:
#             raise TypeError("Invalid argument type for")
#     else:
#         if hasattr(args[0], "__len__"):
#             return QuantVec(*args)
#         else:
#             return Quantity(*args)


from six import string_types, integer_types
from ..quanta import quantity
import numpy
import re

def _format_date(val, unit):
    """
    Format dates.
    :param val: Value (just the value, not a quantity)
    :param unit: Unit. Should be 'rad' or 's'
    :return: A string representation of this date.

    >>> _format_date(4914741782.503475, 's')
    "14-Aug-2014/14:03:03"
    """
    if val == numpy.floor(val) and unit == 'd':
        # Do not show time part if 0
        return quantity(val, unit).formatted('YMD_ONLY')
    else:
        return quantity(val, unit).formatted('DMY')


def _format_quantum(val, unit):
    """
    Format a quantity with reasonable units.
    :param val: The value (just the value, not a quantity)
    :param unit: Unit (something that can be fed to quanta).
    :return: A string representation of this quantity.

    >>> _format_quantum(3, 'm')
    "3 m"
    >>> _format_quantum(4914741782.503475, 's')
    "4.91474e+09 s"
    """

# Path: casacore/quanta/quantity.py
# def quantity(*args):
#     """Create a quantity. This can be from a scalar or vector.
# 
#     Example::
# 
#       q1 = quantity(1.0, "km/s")
#       q2 = quantity("1km/s")
#       q1 = quantity([1.0,2.0], "km/s")
# 
#     """
#     if len(args) == 1:
#         if isinstance(args[0], string_types):
#             # use copy constructor to create quantity from string
#             return Quantity(from_string(args[0]))
#         elif isinstance(args[0], dict):
#             if hasattr(args[0]["value"], "__len__"):
#                 return QuantVec(from_dict_v(args[0]))
#             else:
#                 return Quantity(from_dict(args[0]))
#         elif isinstance(args[0], Quantity) or isinstance(args[0], QuantVec):
#             return args[0]
#         else:
#             raise TypeError("Invalid argument type for")
#     else:
#         if hasattr(args[0], "__len__"):
#             return QuantVec(*args)
#         else:
#             return Quantity(*args)


# Path: casacore/tables/tablehelper.py
from six import string_types, integer_types
from ..quanta import quantity
import numpy
import re


def _format_date(val, unit):
    """
    Format dates.
    :param val: Value (just the value, not a quantity)
    :param unit: Unit. Should be 'rad' or 's'
    :return: A string representation of this date.

    >>> _format_date(4914741782.503475, 's')
    "14-Aug-2014/14:03:03"
    """
    if val == numpy.floor(val) and unit == 'd':
        # Do not show time part if 0
        return quantity(val, unit).formatted('YMD_ONLY')
    else:
        return quantity(val, unit).formatted('DMY')


def _format_quantum(val, unit):
    """
    Format a quantity with reasonable units.
    :param val: The value (just the value, not a quantity)
    :param unit: Unit (something that can be fed to quanta).
    :return: A string representation of this quantity.

    >>> _format_quantum(3, 'm')
    "3 m"
    >>> _format_quantum(4914741782.503475, 's')
    "4.91474e+09 s"
    """

    q = quantity(val, unit)