I'm currently attempting to understand without much success the implementation of VTIMEZONE component using the iCalendar gem.
I'm generating an ics formatted event calendar, unfortunately when importing event in Google Calendar (as an example), I'm getting wrong date and time due to the missing VTIMEZONE component in the generated calendar.
Writing down the VTIMEZONE component plain text is not really difficult, but I would like to be generated dynamically depending on a ActiveSupport::TimeZone I set in the application.
I explored several leads without success. The closer I came was to get the TZInfo object using ActiveSupport::TimeZone.find_tzinfo() method. But then how can I get the various component items needed to declare both Daylight and Standard VTIMEZONE component?
Is there any gem existing or can I do it natively using TZInfo. Going through all ruby docs I could find didn't help much. Any advice, leads are welcome.
Never mind, there is something existing in icalendar that does that.
https://github.com/icalendar/icalendar/blob/master/lib/icalendar/tzinfo.rb
Did not dig deep enough the first time.
require 'icalendar/tzinfo'
estart = DateTime.new(2008, 12, 29, 8, 0, 0)
tstring = "America/Chicago"
cal = Calendar.new
tz = TZInfo::Timezone.get(tstring)
timezone = tz.ical_timezone(estart)
cal.add(timezone)
cal.event do
...
end
cal.to_ical
Related
Hi I was trying send meeting invites through my asp.net MVC application. There was a requirement to show which timezone this invite was created as in following image. I tried various things as told by Microsoft support, neither of them worked.
As per Microsoft Exchange Server support's advice I created following.
TZID:Sri Jayawardenepura
BEGIN:STANDARD
TZOFFSETFROM:+0530
TZOFFSETTO:+0530
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=Sri Jayawardenepura:20140416T033000Z
DTSTAMP:20140327T113138Z
DTEND;TZID=Sri Jayawardenepura:20140416T060000Z
LOCATION: Board room
After adding TZID inside DTSTART, it is not coming as invite to gmail.
but following works fine as invitation both in outlook configured with Exchange Server and webmails like gmail.
TZID:Sri Jayawardenepura
BEGIN:STANDARD
TZOFFSETFROM:+0530
TZOFFSETTO:+0530
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART:20140318T033000Z
DTSTAMP:20140327T122640Z
DTEND:20140318T060000Z
LOCATION: Board room
however that requirement of showing timezone where invite was created not fulfilled yet.
Can anyone help me. Thanks in advance.
If you look at http://www.kanzaki.com/docs/ical/dateTime.html it states that UTC time is identified by a Z suffix character as well as The TZID property parameter MUST NOT be applied to DATE-TIME properties whose time values are specified in UTC.
I would suspect that if you are using a timezone identifier that you need to remove the Z from the end of the date to get it to work properly.
EDIT: So, I was having troubles with timezones before as well, so I had only used UTC time, however I just got one to work with a timezone, so I hope this helps. Inside VTIMEZONE, you have a STANDARD, but you do not have a DTSTART inside the STANDARD. Again, quoting from the above link, The standard or daylight component MUST include the "DTSTART", "TZOFFSETFROM" and "TZOFFSETTO" properties.
It is not RFC5545 compliant but many calendars will expect a TZID to be compatible with the Olson DB and also may expect to have the calendar property X-WR-TIMEZONE set.
What I have seen is that when doing all of above you increase your calendar compatibility ratio.
I need to save Date Time in the (oracle) database in one column, which is sqlType of timestamp (looks like 01-JAN-14 12.00.00.000000 AM). While learning grails I've been using the Joda lib with it's "time picker".
The Joda timepicker has worked well, but now that I'm looking to go primetime I'm looking for something a little more user friendly. Frankly, text boxes might be more user friendly than the drops downs joda gives you.
Anyway, I'd like to remove joda and use something like this:
http://trentrichardson.com/examples/timepicker/
but I can't figure out how to implement it in grails. In my view, if I put:
<input type="text" name="endDate" id="endDate" value="${exampleInstance?.endDate}" />
in place of the g:datePicker, it works fine (the picker that is), except nothing gets saved to the database, and no errors are generated. I hit Save and the Show view comes up with an empty endDate field. Do I need more input tags?
Is there some easy way to implement a modern looking date+time picker that I've missed?
Furthermore, I see there is a plugin for this picker here
http://grails.org/plugin/jquery-ui-timepicker
But being that there isn't any documentation, I'm not sure how to use that either (?)
ANSWER
in controller save/update put something like:
def endDate = params.date('endDate', 'yy-MM-dd h:mm')
//println "Date from Picker was "+endDate
params.endDate = endDate
No further casting was necessary being that it ended up I could format the datepicker control to a very close format as what's in the database, but had I needed to cast from one odd format, or a string, to another, I toyed with this code, which is more psuedo than anything as I was thinking through the process (I'm sure there's a totally Groovy way to do this same thing):
SimpleDateFormat inputFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss.S");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy h.mm.ss.S a");
def v = params.endDate
Date date = inputFormat.parse(v);
String temp = sdf.format(date)
Date dateOut = sdf.parse(temp)
println dateOut
The datepicker, is your UI component therefore, you can have any library that you wish for UI and anything else for back-end. Mostly they are easy to implement, if they provide a little bit of documentation!!.
The timepicker for jQuery ui plugin, that you provided the link, is exposing a resource called jqueryUiTimePicker which depends on jQuery and jQuery-ui. So simply by including this resource into you resources configuration you should be able to utilize it. Its no different than defining your own resource and use it.
About saving issue that you have, on your save pass parameter failOnError:true so you can see the errors if any.
I have created a sample project that utilizes this plugin hope it helps
In your controller, you will need to parse the parameter value to a Date value. Something like,
def endDate = params.date('endDate', 'dd-MM-yyyy')
dd-MM-yyyy is whatever format the jquery plugin submits the date value. (println params for this or look up the plugin documentation)
If you want a date format binding to happen automatically, check the Date Formats For Data Binding in the doc http://grails.org/doc/latest/guide/single.html#dataBinding for a way to globally specify the format
I'm currently trying to work in bootstrap x-editable to my meteor application. I'm using the atmosphere package for this: https://github.com/nate-strauser/meteor-x-editable-bootstrap. I'm having a couple of issue so far which are:
When I select a date using the date data-type I get a javascript date object back that is 4 hours behind what I actually picked(assuming this is because I'm in -4 timezone).
When I edit a textarea, the line breaks are saved to the database, but when bring up the editable to edit it the line breaks are striped.
It looks like this might be the intended behavior. Its hard to be sure without more information.
With the date, javascript stores date in unixtime. This is because its very easy to switch timezones and not worry about having javascript itself having to keep track of DST and the other complications of keeping time.
If you use new Date(<the javascript timestamp>); you should get the time in your timezone.
With the textarea it looks like some kind of text-encoding conversion is taking place. You should check to see what the character codes of those stripes are and convert them to newlines like \n. One scenario this could occur is if you're copy-pasting stuff with a different encoding into the textarea.
I'm trying to parse a unformatted string which contains a date (e.g. today = "08082013") to the format "08.08.2013".
This works:
(.parse (java.text.SimpleDateFormat. "ddMMyyyy") today) => <Date Sun Jan 01 00:00:00 CET 1950>
But when I do (.parse (java.text.SimpleDateFormat. "dd.MM.yyyy") today) I get the error "Unparseable date: "08082013"
Why? How can I get my desired date format?
To get from string to date, use parse.
To get from date to string, use format.
Both use a formatter to describe the transition.
=>(.format
(java.text.SimpleDateFormat. "dd.MM.yyyy")
(.parse
(java.text.SimpleDateFormat. "ddMMyyyy")
"08082013"))
"08.08.2013"
If you are playing around with date and time I recommend checking out this Clojure lib,
https://github.com/clj-time/clj-time
It is kind of the time lib most Clojure programmers use, and is based on the java lib joda time, that by many is agreed to be better than the Java build in one.
The .parse method of SimpleDateFormat will not generate a string, it will read a string and generate a java.util.Date object. If you want to generate a dotted string, you need SimpleDateFormat with the dots in place and call .format on it, given a java.util.Date.
See http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html or take a look at clj-time
Using clj-time, you can use this:
(defn format-date
[date-str]
(f/unparse (f/formatter "dd.MM.yyyy") (f/parse custom-formatter date-str)))
(format-date "08082013") ;=> "08.08.2013"
Clojure is based on Java, so many of your options will end up calling Java in the end. The way I understand it, Java has two time apis. The old one is at java.text.SimpleDateFormat and is not recommended anymore. The new one is under java.time and is "much better".
With that in mind, you have several options for date manipulation in Clojure:
You can call either the new or old Java functions directly. NeilsK's answer provides examples on how to do this with the old api. You should be able to adapt it fairly easily to the new java.time api with some help from the Clojure documentation on java interop.
Everyone is saying use clj-time but I would not recommend it as it's based on a Java library called JodaTime which was deprecated when Java's new time API came out.
I personally have had a lot of success with a library called clojure.java-time which is a simple Clojure wrapper for Java's new time api.
juxt/tick looks very promising as it seeks to provide that new api in a clojure-friendly format across not only java platforms, but also in the browser and on dotnet. It was in alpha at the time of this writing but I will be keeping an eye on it.
I'm trying to get messages after a certain time-stamp, the way I've coded it was suggested by another programmer in this site:
GregorianCalendar date = new GregorianCalendar();
SearchTerm newer = new ReceivedDateTerm(ComparisonTerm.GT,date.getTime());
Message msgs[] = folder.search(newerThen);
The issue is that I get all the messages since the date, not the specific time. I was wondering if there is some work-around to emulate this. I mean, for an instance, if I want to get all the messages since today in the midday I would get those messages spicifically and not those ones received in today's morning.
Thanks in advance,
EDIT:
A new thought concerning to this: perhaps some date manipulation could do the job. I mean, comparing the minutes in the timestamp and filter programmatically those messages that don't fit the criteria. I know it's not the best way, but it could work.
PS: I'm using IMAP and trying to get mails from gmail, but I guess it should work no matter what the mail-server is.
Unfortunately, no. In this case, the IMAP protocol is being used by the JavaMail classes, and IMAP's SEARCH command takes only dates, not times (see the SINCE and SENTSINCE criteria).
You could use the setTime() method to query for some specific time.
Example:
setTime(timeInMilliseconds)