Skip to content
This repository
Browse code

Cleaned up w3cdtf-date function by Daniel Kaminski.

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@923 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit 9ea26900488e15c620a83082c258db299adcb1ee 1 parent 081c135
authored October 04, 2005

Showing 1 changed file with 42 additions and 35 deletions. Show diff stats Hide diff stats

  1. 77  src/yaws_rss.erl
77  src/yaws_rss.erl
@@ -384,42 +384,49 @@ to_xml([{Title, Link, Desc, Creator, GregSecs}|Tail]) ->
384 384
 to_xml([]) -> 
385 385
     [].
386 386
 
  387
+%%%
  388
+%%% Create W3CDTF (http://www.w3.org/TR/NOTE-datetime) formatted date
  389
+%%% w3cdtf(GregSecs) -> "YYYY-MM-DDThh:mm:ssTZD"
  390
+%%%
  391
+w3cdtf(GregSecs) ->    Date = calendar:gregorian_seconds_to_datetime(GregSecs),
  392
+    {{Y, Mo, D},{H, Mi, S}} = Date,
  393
+    [UDate|_] = calendar:local_time_to_universal_time_dst(Date),
  394
+    {DiffD,{DiffH,DiffMi,_}}=calendar:time_difference(UDate,Date),
  395
+    w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi). 
  396
+
  397
+%%%  w3cdtf's helper function
  398
+w3cdtf_diff(Y, Mo, D, H, Mi, S, _DiffD, DiffH, DiffMi) when DiffH < 12,  DiffH /= 0 ->
  399
+    i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
  400
+        add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":"  ++
  401
+        add_zero(S) ++ "+" ++ add_zero(DiffH) ++ ":"  ++ add_zero(DiffMi);
  402
+
  403
+w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12,  DiffD == 0 ->
  404
+    i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
  405
+        add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":"  ++
  406
+        add_zero(S) ++ "+" ++ add_zero(DiffH) ++ ":"  ++
  407
+        add_zero(DiffMi);
  408
+
  409
+w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12,  DiffD /= 0, DiffMi /= 0 ->
  410
+    i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
  411
+        add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":"  ++
  412
+        add_zero(S) ++ "-" ++ add_zero(23-DiffH) ++
  413
+        ":" ++ add_zero(60-DiffMi);
  414
+
  415
+w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12,  DiffD /= 0, DiffMi == 0 ->
  416
+   i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
  417
+        add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":"  ++
  418
+        add_zero(S) ++ "-" ++ add_zero(24-DiffH) ++
  419
+        ":" ++ add_zero(DiffMi); 
  420
+
  421
+w3cdtf_diff(Y, Mo, D, H, Mi, S, _DiffD, DiffH, _DiffMi) when DiffH == 0 ->
  422
+    i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
  423
+        add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":"  ++
  424
+        add_zero(S) ++ "Z".
  425
+
  426
+add_zero(I) when integer(I) -> add_zero(i2l(I));
  427
+add_zero([A])               -> [$0,A];
  428
+add_zero(L) when list(L)    -> L. 
387 429
 
388  
-w3cdtf(GregSecs)->      Date = calendar:gregorian_seconds_to_datetime(GregSecs),
389  
-      {{Y,Mo,D},{H, Mi, S}} = Date,
390  
-      [UDate|_] = calendar:local_time_to_universal_time_dst(Date),
391  
-      {DiffD,{DiffH,DiffMi,_}}=calendar:time_difference(UDate,Date),
392  
-      if
393  
-         DiffH<12 -> 
394  
-	      i2l(Y) ++ "-" ++ add_zero(i2l(Mo)) ++ "-"
395  
-		  ++ add_zero(i2l(D)) ++ "T" ++ add_zero(i2l(H)) ++
396  
-		  ":" ++ add_zero(i2l(Mi)) ++ ":"
397  
-		  ++ add_zero(i2l(S)) ++
398  
-		  "+" ++ add_zero(i2l(DiffH)) ++ ":"
399  
-		  ++ add_zero(i2l(DiffMi));
400  
-         DiffH>12,DiffD==0 -> 
401  
-	      i2l(Y) ++ "-" ++ add_zero(i2l(Mo)) ++ "-"
402  
-		  ++ add_zero(i2l(D)) ++ "T" ++ add_zero(i2l(H)) ++
403  
-		  ":" ++ add_zero(i2l(Mi)) ++ ":"
404  
-		  ++ add_zero(i2l(S)) ++
405  
-		  "+" ++ add_zero(i2l(DiffH)) ++ ":"
406  
-		  ++ add_zero(i2l(DiffMi));
407  
-         DiffH>12,DiffD/=0 -> 
408  
-	      i2l(Y) ++ "-" ++ add_zero(i2l(Mo)) ++ "-"
409  
-		  ++ add_zero(i2l(D)) ++ "T" ++ add_zero(i2l(H)) ++
410  
-		  ":" ++ add_zero(i2l(Mi)) ++ ":"
411  
-		  ++ add_zero(i2l(S)) ++
412  
-		  "-" ++ add_zero(i2l(24-DiffH)) ++ ":"
413  
-		  ++ add_zero(i2l(if DiffMi==0 -> DiffMi;DiffMi/=0 ->60-DiffMi end));
414  
-         DiffH==0 -> 
415  
-	      i2l(Y) ++ "-" ++ add_zero(i2l(Mo)) ++ "-"
416  
-		  ++ add_zero(i2l(D)) ++ "T" ++ add_zero(i2l(H)) ++
417  
-		  ":" ++ add_zero(i2l(Mi)) ++ ":"
418  
-		  ++ add_zero(i2l(S)) ++ "Z"
419  
-      end. 
420  
-
421  
-add_zero([A]) -> [$0,A];
422  
-add_zero(L)   -> L.
423 430
 
424 431
 
425 432
 get_db_mod(Opts, Def)  -> lkup(db_mod, Opts, Def).

0 notes on commit 9ea2690

Please sign in to comment.
Something went wrong with that request. Please try again.