Datum vergleichen

Django, Flask, Bottle, WSGI, CGI…
Antworten
MrsBean

Hallo!

Wie kann ich in Zope das aktuelle Datum mit einem Stringdatum vergleichen? Muss ich dazu Python benutzen oder geht das auch mit DTML?


mfg, Bean :D
xturbo77
User
Beiträge: 39
Registriert: Montag 9. September 2002, 20:05
Kontaktdaten:

MrsBean hat geschrieben:Hallo!

Wie kann ich in Zope das aktuelle Datum mit einem Stringdatum vergleichen? Muss ich dazu Python benutzen oder geht das auch mit DTML?


mfg, Bean :D

Code: Alles auswählen

<dtml-if expr="_.DateTime().strftime('%d.%m.%Y')=='04.09.2003'">
  Heute ist der 04.09.03
<dtml-else>
  Heute ist nicht der 04.09.03
</dtml-if>
MrsBean

Hi!

Danke für die Antwort! Ich hab das jetzt ausprobiert, und zwar soll in meinem script jahreszeitspezifisch das Bild geändert werden.
Leider zeigt er mir immer an, dass es Herbst ist, auch wenn ich die Systemzeit umstelle. Woran kann das liegen? Was ist falsch an dem Code?

Code: Alles auswählen

<dtml-if expr="_.DateTime().strftime('%d.%m.%Y')>='21.06.03' and _.DateTime().strftime('%d.%m.%Y')<'01.09.03'"> 
  <dtml-var Sommer.jpg>Es ist Sommer!
</dtml-if>
<dtml-if expr="_.DateTime().strftime('%d.%m.%Y')>='01.09.03' and _.DateTime().strftime('%d.%m.%Y')<'22.11.03'">  
  <dtml-var Herbst.jpg>Es ist Herbst!
</dtml-if>
<dtml-if expr="_.DateTime().strftime('%d.%m.%Y')>='22.11.03' and _.DateTime().strftime('%d.%m.%Y')<'21.03.04'">  
  <dtml-var Winter.jpg>Es ist Winter!
</dtml-if>
<dtml-if expr="_.DateTime().strftime('%d.%m.%Y')>='21.03.04' and _.DateTime().strftime('%d.%m.%Y')<'21.06.04'">  
  <dtml-var Fruehling.jpg>Es ist Frühling!
</dtml-if>
Bean :D :D
xturbo77
User
Beiträge: 39
Registriert: Montag 9. September 2002, 20:05
Kontaktdaten:

Hm, also zuerst würde ich checken ob das Datum wirklich umgestellt ist.
Du kannst es dir mit

Code: Alles auswählen

<dtml-var ZopeTime>
anzeigen lassen.

Ist das Datum ok, und wird dennoch das falsche Bild angezeigt, schau dir mal die Klasse DateTime an -> http://zope.org/Documentation/Books/Zop ... endixB.stx
Da gibt es ein paar Funktionen die dich vielleicht weiterbringen.

greaterThanEqualTo(t)
Compare this DateTime object to another DateTime object OR a floating point number such as that which is returned by the python time module. Returns true if the object represents a date/time greater than or equal to the specified DateTime or time module style time. Revised to give more correct results through comparison of long integer milliseconds.

greaterThan(t)
Compare this DateTime object to another DateTime object OR a floating point number such as that which is returned by the python time module. Returns true if the object represents a date/time greater than the specified DateTime or time module style time. Revised to give more correct results through comparison of long integer milliseconds.

lessThanEqualTo(t)
Compare this DateTime object to another DateTime object OR a floating point number such as that which is returned by the python time module. Returns true if the object represents a date/time less than or equal to the specified DateTime or time module style time. Revised to give more correct results through comparison of long integer milliseconds.

lessThan(t)
Compare this DateTime object to another DateTime object OR a floating point number such as that which is returned by the python time module. Returns true if the object represents a date/time less than the specified DateTime or time module style time. Revised to give more correct results through comparison of long integer milliseconds.

Damit kannst du DateObjekte vergleichen, ist vermutlich besser als Strings mit grösser/kleiner zu vergleichen.

Code: Alles auswählen

<dtml-if expr="_.DateTime().greaterThanEqualTo(_.DateTime('21.06.03')) 
               and
               _.DateTime().lessThan(_.DateTime('01.09.03'))"> 

  <dtml-var Sommer.jpg>Es ist Sommer! 

</dtml-if>
Antworten