hesseflux.ascii2ascii

ascii2ascii : Convert date notations between different regional variants
such as English YYYY-MM-DD hh:mm:ss and US-English MM/DD/YYYY hh:mm:ss formats.

This module was written by Matthias Cuntz while at Department of Computational Hydrosystems, Helmholtz Centre for Environmental Research - UFZ, Leipzig, Germany, and continued while at Institut National de Recherche pour l’Agriculture, l’Alimentation et l’Environnement (INRAE), Nancy, France.

Copyright (c) 2015-2020 Matthias Cuntz - mc (at) macu (dot) de Released under the MIT License; see LICENSE file for details.

  • Written Feb 2015 by Matthias Cuntz (mc (at) macu (dot) de)
  • Removed usage of date2dec and dec2date, Nov 2016, Matthias Cuntz
  • Adapted docstrings to Python 2 and 3, Nov 2016, Matthias Cuntz
  • Added us and fr keywords, renamed eng to en, Mar 2018, Matthias Cuntz
  • Added two-digit year, Nov 2018, Matthias Cuntz
  • Removed bug from usage of en and old name eng, Jun 2019, Matthias Cuntz
  • Using numpy docstring format, May 2020, Matthias Cuntz

The following functions are provided

ascii2ascii(edate[, full, en, fr, us, eng, YY]) Convert date notations between ascii DD.MM.YYYY hh:mm:ss, English YYYY-MM-DD hh:mm:ss, American MM/DD/YYYY hh:mm:ss, and French DD/MM/YYYY hh:mm:ss.
ascii2en(edate, **kwarg) Wrapper function for ascii2ascii() with English date format output, i.e. en=True:
ascii2fr(edate, **kwarg) Wrapper function for ascii2ascii() with French date format output, i.e. fr=True:
ascii2us(edate, **kwarg) Wrapper function for ascii2ascii() with US-English date format output, i.e. us=True:
ascii2eng(edate, **kwarg) Wrapper function for ascii2ascii() with English date format output, i.e. en=True:
en2ascii(edate, **kwarg) Wrapper function for ascii2ascii with ascii date format output (default):
fr2ascii(edate[, full, YY]) Convert French date notation DD/MM/YYYY hh:mm:ss to ascii notation DD.MM.YYYY hh:mm:ss.
us2ascii(edate, **kwarg) Wrapper function for ascii2ascii() with ascii date format output (default):
eng2ascii(edate, **kwarg) Wrapper function for ascii2ascii() with ascii date format output (default):
ascii2ascii(edate, full=False, en=False, fr=False, us=False, eng=False, YY=False)[source]

Convert date notations between ascii DD.MM.YYYY hh:mm:ss, English YYYY-MM-DD hh:mm:ss, American MM/DD/YYYY hh:mm:ss, and French DD/MM/YYYY hh:mm:ss. Input can only be ascii, English and American. Output can also be French DD/MM/YYYY hh:mm:ss. Use fr2ascii first for French input formats.

Parameters:
  • edate (array_like) – date strings in ascii, English or American format.
  • full (bool, optional) –

    True: output dates arr all in full format DD.MM.YYYY hh:mm:ss; missing time inputs are 00 on output

    False: output dates are as long as input dates (default),
    e.g. [YYYY-MM-DD, YYYY-MM-DD hh:mm] gives [DD.MM.YYYY, DD.MM.YYYY hh:mm]
  • en (bool, optional) – True: output format is English YYYY-MM-DD hh:mm:ss (default: False)
  • fr (bool, optional) – True: output format is French DD/MM/YYYY hh:mm:ss (default: False)
  • us (bool, optional) – True: output format is American MM/DD/YYYY hh:mm:ss (default: False)
  • YY (bool, optional) – Year in input file is 2-digit year. Every year that is above the current year will be taken as being in 1900 (default: False).
  • eng (bool, optional) – Same as en: obsolete.
Returns:

date – date strings in chosen date format. If no optional keyword True then output is in ascii format: DD.MM.YYYY hh:mm:ss. The output type will be the same as the type of the input.

Return type:

array_like

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> print(", ".join(ascii2ascii(edate)))
12.11.2014 12:00, 01.03.2015 17:56:00, 01.12.1990, 04.05.1786
>>> print(", ".join(ascii2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00, 04.05.1786 00:00:00
>>> print(", ".join(ascii2ascii(edate, en=True)))
2014-11-12 12:00, 2015-03-01 17:56:00, 1990-12-01, 1786-05-04
>>> print(", ".join(ascii2ascii(edate, en=True, full=True)))
2014-11-12 12:00:00, 2015-03-01 17:56:00, 1990-12-01 00:00:00, 1786-05-04 00:00:00
>>> print(ascii2ascii(list(edate)))
['12.11.2014 12:00', '01.03.2015 17:56:00', '01.12.1990', '04.05.1786']
>>> print(ascii2ascii(tuple(edate)))
('12.11.2014 12:00', '01.03.2015 17:56:00', '01.12.1990', '04.05.1786')
>>> print(ascii2ascii(np.array(edate)))
['12.11.2014 12:00' '01.03.2015 17:56:00' '01.12.1990' '04.05.1786']
>>> print(ascii2ascii(edate[0]))
12.11.2014 12:00
>>> print(", ".join(ascii2ascii(edate, us=True)))
11/12/2014 12:00, 03/01/2015 17:56:00, 12/01/1990, 05/04/1786
>>> print(", ".join(ascii2ascii(ascii2ascii(edate, en=True), us=True, full=True)))
11/12/2014 12:00:00, 03/01/2015 17:56:00, 12/01/1990 00:00:00, 05/04/1786 00:00:00
>>> print(", ".join(ascii2ascii(edate, fr=True)))
12/11/2014 12:00, 01/03/2015 17:56:00, 01/12/1990, 04/05/1786
>>> print(", ".join(ascii2ascii(edate, fr=True, full=True)))
12/11/2014 12:00:00, 01/03/2015 17:56:00, 01/12/1990 00:00:00, 04/05/1786 00:00:00

# YY=True >>> edate = [‘14-11-12 12:00’, ‘01.03.15 17:56:00’, ‘90-12-01’] >>> print(“, “.join(ascii2ascii(edate, YY=True))) 12.11.2014 12:00, 01.03.2015 17:56:00, 01.12.1990 >>> print(“, “.join(ascii2ascii(edate, en=True, YY=True))) 2014-11-12 12:00, 2015-03-01 17:56:00, 1990-12-01 >>> print(“, “.join(ascii2ascii(edate, us=True, YY=True))) 11/12/2014 12:00, 03/01/2015 17:56:00, 12/01/1990 >>> print(“, “.join(ascii2ascii(ascii2ascii(edate, en=True, YY=True), us=True, full=True))) 11/12/2014 12:00:00, 03/01/2015 17:56:00, 12/01/1990 00:00:00 >>> print(“, “.join(ascii2ascii(edate, fr=True, full=True, YY=True))) 12/11/2014 12:00:00, 01/03/2015 17:56:00, 01/12/1990 00:00:00

ascii2en(edate, **kwarg)[source]
Wrapper function for ascii2ascii() with English date format output, i.e. en=True:
ascii2ascii(edate, en=True, **kwarg)

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> print(", ".join(ascii2en(edate)))
2014-11-12 12:00, 2015-03-01 17:56:00, 1990-12-01, 1786-05-04
>>> print(", ".join(ascii2en(edate, full=True)))
2014-11-12 12:00:00, 2015-03-01 17:56:00, 1990-12-01 00:00:00, 1786-05-04 00:00:00
>>> edate = ['14-11-12 12:00', '01.03.15 17:56:00', '90-12-01']
>>> print(", ".join(ascii2en(edate, full=True, YY=True)))
2014-11-12 12:00:00, 2015-03-01 17:56:00, 1990-12-01 00:00:00
ascii2fr(edate, **kwarg)[source]
Wrapper function for ascii2ascii() with French date format output, i.e. fr=True:
ascii2ascii(edate, fr=True, **kwarg)

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> print(", ".join(ascii2fr(edate)))
12/11/2014 12:00, 01/03/2015 17:56:00, 01/12/1990, 04/05/1786
>>> print(", ".join(ascii2fr(edate, full=True)))
12/11/2014 12:00:00, 01/03/2015 17:56:00, 01/12/1990 00:00:00, 04/05/1786 00:00:00
>>> edate = ['14-11-12 12:00', '01.03.15 17:56:00', '90-12-01']
>>> print(", ".join(ascii2fr(edate, full=True, YY=True)))
12/11/2014 12:00:00, 01/03/2015 17:56:00, 01/12/1990 00:00:00
ascii2us(edate, **kwarg)[source]
Wrapper function for ascii2ascii() with US-English date format output, i.e. us=True:
ascii2ascii(edate, us=True, **kwarg)

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> print(", ".join(ascii2ascii(edate, us=True)))
11/12/2014 12:00, 03/01/2015 17:56:00, 12/01/1990, 05/04/1786
>>> print(", ".join(ascii2ascii(ascii2ascii(edate, en=True), us=True, full=True)))
11/12/2014 12:00:00, 03/01/2015 17:56:00, 12/01/1990 00:00:00, 05/04/1786 00:00:00
>>> edate = ['14-11-12 12:00', '01.03.15 17:56:00', '90-12-01']
>>> print(", ".join(ascii2ascii(ascii2ascii(edate, en=True, YY=True), us=True, full=True)))
11/12/2014 12:00:00, 03/01/2015 17:56:00, 12/01/1990 00:00:00
ascii2eng(edate, **kwarg)[source]
Wrapper function for ascii2ascii() with English date format output, i.e. en=True:
ascii2ascii(edate, en=True, **kwarg)

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> print(", ".join(ascii2eng(edate)))
2014-11-12 12:00, 2015-03-01 17:56:00, 1990-12-01, 1786-05-04
>>> print(", ".join(ascii2eng(edate, full=True)))
2014-11-12 12:00:00, 2015-03-01 17:56:00, 1990-12-01 00:00:00, 1786-05-04 00:00:00
>>> edate = ['14-11-12 12:00', '01.03.15 17:56:00', '90-12-01']
>>> print(", ".join(ascii2eng(edate, full=True, YY=True)))
2014-11-12 12:00:00, 2015-03-01 17:56:00, 1990-12-01 00:00:00
en2ascii(edate, **kwarg)[source]
Wrapper function for ascii2ascii with ascii date format output (default):
ascii2ascii(edate, **kwarg)

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> edate = ascii2ascii(edate, en=True)
>>> print(", ".join(en2ascii(edate)))
12.11.2014 12:00, 01.03.2015 17:56:00, 01.12.1990, 04.05.1786
>>> print(", ".join(en2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00, 04.05.1786 00:00:00
>>> edate = ['14-11-12 12:00', '01.03.15 17:56:00', '90-12-01']
>>> edate = ascii2ascii(edate, en=True, YY=True)
>>> print(", ".join(en2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00
fr2ascii(edate, full=False, YY=False)[source]

Convert French date notation DD/MM/YYYY hh:mm:ss to ascii notation DD.MM.YYYY hh:mm:ss. Simply replaces ‘/’ with ‘.’, assuring iterable type.

Parameters:
  • edate (array_like) – date strings in French date format DD/MM/YYYY [hh:mm:ss]
  • full (bool, optional) –

    True: output dates arr all in full format DD.MM.YYYY hh:mm:ss; missing time inputs are 00 on output

    False: output dates are as long as input dates (default),
    e.g. [DD/MM/YYYY, DD/MM/YYYY hh:mm] gives [DD.MM.YYYY, DD.MM.YYYY hh:mm]
  • YY (bool, optional) – Year in input file is 2-digit year. Every year that is above the current year will be taken as being in 1900 (default: False).
Returns:

date – date strings in ascii date format: DD.MM.YYYY hh:mm:ss. The output type will be the same as the type of the input.

Return type:

array_like

Examples

>>> edate = ['12/11/2014 12:00', '01/03/2015 17:56:00', '01/12/1990', '04/05/1786']
>>> print(", ".join(fr2ascii(edate)))
12.11.2014 12:00, 01.03.2015 17:56:00, 01.12.1990, 04.05.1786
>>> print(", ".join(fr2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00, 04.05.1786 00:00:00
>>> print(fr2ascii(list(edate)))
['12.11.2014 12:00', '01.03.2015 17:56:00', '01.12.1990', '04.05.1786']
>>> print(fr2ascii(tuple(edate)))
('12.11.2014 12:00', '01.03.2015 17:56:00', '01.12.1990', '04.05.1786')
>>> print(fr2ascii(np.array(edate)))
['12.11.2014 12:00' '01.03.2015 17:56:00' '01.12.1990' '04.05.1786']
>>> print(fr2ascii(edate[0]))
12.11.2014 12:00

# YY=True >>> edate = [‘12/11/14 12:00’, ‘01/03/15 17:56:00’, ‘01/12/90’] >>> print(“, “.join(fr2ascii(edate, YY=True))) 12.11.2014 12:00, 01.03.2015 17:56:00, 01.12.1990

>>> print(", ".join(fr2ascii(edate, full=True, YY=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00
us2ascii(edate, **kwarg)[source]
Wrapper function for ascii2ascii() with ascii date format output (default):
ascii2ascii(edate, **kwarg)

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> edate = ascii2ascii(edate, us=True)
>>> print(", ".join(us2ascii(edate)))
12.11.2014 12:00, 01.03.2015 17:56:00, 01.12.1990, 04.05.1786
>>> print(", ".join(us2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00, 04.05.1786 00:00:00
>>> edate = ['14-11-12 12:00', '01.03.15 17:56:00', '90-12-01']
>>> edate = ascii2ascii(edate, us=True, YY=True)
>>> print(", ".join(us2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00
eng2ascii(edate, **kwarg)[source]
Wrapper function for ascii2ascii() with ascii date format output (default):
ascii2ascii(edate, **kwarg)

Examples

>>> edate = ['2014-11-12 12:00', '01.03.2015 17:56:00', '1990-12-01', '04.05.1786']
>>> edate = ascii2ascii(edate, en=True)
>>> print(", ".join(eng2ascii(edate)))
12.11.2014 12:00, 01.03.2015 17:56:00, 01.12.1990, 04.05.1786
>>> print(", ".join(eng2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00, 04.05.1786 00:00:00
>>> edate = ['14-11-12 12:00', '01.03.15 17:56:00', '90-12-01']
>>> edate = ascii2ascii(edate, en=True, YY=True)
>>> print(", ".join(eng2ascii(edate, full=True)))
12.11.2014 12:00:00, 01.03.2015 17:56:00, 01.12.1990 00:00:00