Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created December 3, 2018 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/79dcb402afe079c89dc117a425412e1a to your computer and use it in GitHub Desktop.
Save Fhernd/79dcb402afe079c89dc117a425412e1a to your computer and use it in GitHub Desktop.
_formatos = {
'amd': '{d.aghnio}-{d.mes}-{d.dia}',
'mda': '{d.mes}/{d.dia}/{d.aghnio}',
'dma': '{d.dia}/{d.mes}/{d.aghnio}'
}
class Fecha:
def __init__(self, agnhio, mes, dia):
self.aghnio = agnhio
self.mes = mes
self.dia = dia
def __format__(self, codigo_formato):
if codigo_formato == '':
codigo_formato = 'amd'
formato = _formatos[codigo_formato]
return formato.format(d=self)
fecha = Fecha(2018, 11, 30)
print(format(fecha))
print(format(fecha, 'mda'))
print('La fecha es {:amd}'.format(fecha))
print('La fecha es {:mda}'.format(fecha))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment