AS3: Creating a Google Calendar RF3339 Timestamp


/ Published in: ActionScript 3
Save to your folder(s)

If you ever need to build a Flash mash-up on top of Google Calendar, you may need sync things through a timestamp. This example basically makes a request to my public Google calendar profile and says, "Give me any data based on what is happening right now". So the URL Request looks like this "http://www.google.com/calendar/feeds/MyCalendarFeed/public/basic?start-min=" + RF3339.timestamp();


Copy this code and paste it in your HTML
  1. /*
  2.  * Timestampe to RF3339 Google Calendar Spec
  3.  *
  4. */
  5. package com.chrisaiv
  6. {
  7. public class RF3339
  8. {
  9. public function RF3339()
  10. {
  11. }
  12.  
  13. public static function timestamp(date=null):String
  14. {
  15. date = date ? date : new Date();
  16. var offset = date.getTimezoneOffset();
  17.  
  18. return pad(date.getFullYear(), 4 )
  19. + "-" + pad( date.getMonth() + 1, 2 )
  20. + "-" + pad( date.getDate(), 2 )
  21. + "T" + pad( date.getHours(), 2 )
  22. + ":" + pad( date.getMinutes(), 2 )
  23. + ":" + pad( date.getSeconds(), 2 )
  24. + "." + pad( date.getMilliseconds(), 3 )
  25. + ( offset > 0 ? "-" : "+" )
  26. + pad( Math.floor( Math.abs( offset ) / 60 ), 2 )
  27. + ":" + pad( Math.abs( offset ) % 60, 2 );
  28. }
  29.  
  30. public static function pad(amount, width)
  31. {
  32. var padding = "";
  33. while (padding.length < width - 1 && amount < Math.pow(10, width - padding.length - 1))
  34. {
  35. padding += "0";
  36. }
  37. return padding + amount.toString();
  38. }
  39. }
  40. }

URL: http://snipplr.com/view/44492/javascript-create-rfc-3339-timestamps/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.