Creating a constraint on a Date

Good Afternoon,

I am having difficulty understanding how a date is stored and therefore placing a constraint around a date. I am asking the survey team to enter the date of the last dose of Vitamin A from the respondent's vaccine card; however I only want to document use within a year from the survey date.

I have tried converting my date to an integer and performing an operation assuming that int converted the date to a timestamp in seconds.

. > date(int(today()) - (606024*365))

I have tried using milliseconds.

. > date(int(today()) - (6060243651000))

Any thoughts would be greatly appreciated!

Many thanks in advance.

Regards,

Caitlin

Hi Caitlin,

Subtracting the two dates may be a bit tricky. The following links may help.


2.

Best,

Samson

··· On Sun, Dec 1, 2013 at 9:00 PM, wrote:

Good Afternoon,

I am having difficulty understanding how a date is stored and therefore
placing a constraint around a date. I am asking the survey team to enter
the date of the last dose of Vitamin A from the respondent's vaccine card;
however I only want to document use within a year from the survey date.

I have tried converting my date to an integer and performing an operation
assuming that int converted the date to a timestamp in seconds.

. > date(int(today()) - (606024*365))

I have tried using milliseconds.

. > date(int(today()) - (6060243651000))

Any thoughts would be greatly appreciated!

Many thanks in advance.

Regards,

Caitlin

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Samson Gejibo

PhD candidate

University of Bergen | Department of Informatics
Thormøhelnsgt. 55, Postboks 7800
NO-5020 Bergen

Office: +4755584278
Mobile: +4745137535

http://www.uib.no/persons/Thorkild.Tylleskar#profil

Hi Mitch and Samson,

Thanks so much for your responses! I am not a programmer and therefore not conversant in Java, so I apologize in advance for my superficial understanding of resources you provided.

I have been creating my survey using the XLSform and submitting it for XML conversion on the ODK website.

I tried using your decimal-date-time function on the XLSform. It was accepted without error on the ODK website, but when I tested the constraint on the enketo preview I received the following error.

A formula evaluation error occurred. Please contactsupport@enketo.org with this error:
• Error occurred trying to evaluate: . > date(decimal-date-time(today()) - (6060243651000)), message: Function "{}decimal-date-time" does not exist.

I understand that that new functionality may not be used on the enketo version.

Since it sounds like doing date arithmetic can be complex and imprecise, are there other suggested functions for bounding dates dynamically? I am not wedded to doing arithmetic on a date converted to an integer; it was simply only tool I could think of in my somewhat limited toolbox.

Many thanks for your assistance!

Regards,

Caitlin

··· On Sunday, 1 December 2013 15:00:36 UTC-5, caitlin...@gmail.com wrote: > Good Afternoon, > > I am having difficulty understanding how a date is stored and therefore placing a constraint around a date. I am asking the survey team to enter the date of the last dose of Vitamin A from the respondent's vaccine card; however I only want to document use within a year from the survey date. > > I have tried converting my date to an integer and performing an operation assuming that int converted the date to a timestamp in seconds. > > . > date(int(today()) - (60*60*24*365)) > > I have tried using milliseconds. > > . > date(int(today()) - (60*60*24*365*1000)) > > Any thoughts would be greatly appreciated! > > Many thanks in advance. > > Regards, > > Caitlin

Thanks so much for the responses. I have been using Enketo to preview my questionnaire and test constraints as I do not have consistent access to an android device. I understand that there may be a lag in the availability of functionality.

Thanks again,

Caitlin

··· On Sunday, 1 December 2013 15:00:36 UTC-5, caitlin...@gmail.com wrote: > Good Afternoon, > > I am having difficulty understanding how a date is stored and therefore placing a constraint around a date. I am asking the survey team to enter the date of the last dose of Vitamin A from the respondent's vaccine card; however I only want to document use within a year from the survey date. > > I have tried converting my date to an integer and performing an operation assuming that int converted the date to a timestamp in seconds. > > . > date(int(today()) - (60*60*24*365)) > > I have tried using milliseconds. > > . > date(int(today()) - (60*60*24*365*1000)) > > Any thoughts would be greatly appreciated! > > Many thanks in advance. > > Regards, > > Caitlin

I just updated the versioned link to the Javarosa source -- it was stale.

ODK Collect 1.4 added two functions:

decimal-date-time(${fieldname})

decimal-time(${fieldname})

That give a decimal representation of a date ( 1 == one day, 0.5 == noon).

However, there are many many problems with date handling in ODK Collect.
Most every calculation appears to be tainted with the potential for some
sort of truncation or rounding. So if you need to do date arithmetic, be
aware that you may need to do considerable testing to ensure that it works
as you want it to, and test it in several time zones too, so you know how
that affects your calculations.

Mitch

··· On Sun, Dec 1, 2013 at 2:18 PM, Samson Gejibo wrote:

Hi Caitlin,

Subtracting the two dates may be a bit tricky. The following links may
help.

http://stackoverflow.com/questions/12067697/convert-current-date-as-integer
2.
http://stackoverflow.com/questions/13036907/java-subtract-two-dates-in-this-format

Best,

Samson

On Sun, Dec 1, 2013 at 9:00 PM, caitlin.worrell@gmail.com wrote:

Good Afternoon,

I am having difficulty understanding how a date is stored and therefore
placing a constraint around a date. I am asking the survey team to enter
the date of the last dose of Vitamin A from the respondent's vaccine card;
however I only want to document use within a year from the survey date.

I have tried converting my date to an integer and performing an operation
assuming that int converted the date to a timestamp in seconds.

. > date(int(today()) - (606024*365))

I have tried using milliseconds.

. > date(int(today()) - (6060243651000))

Any thoughts would be greatly appreciated!

Many thanks in advance.

Regards,

Caitlin

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Samson Gejibo

PhD candidate

University of Bergen | Department of Informatics
Thormøhelnsgt. 55, Postboks 7800
NO-5020 Bergen

Office: +4755584278
Mobile: +4745137535

http://www.uib.no/persons/Thorkild.Tylleskar#profil

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

If you are targeting Enketo, then there should be a way to directly use
Javascript functions for dates (I hope), rather than be restricted to just
the functionality that is available in ODK Collect. However, I am not
familiar enough with Enketo to provide guidance on that.

··· On Mon, Dec 2, 2013 at 8:59 PM, wrote:

Hi Mitch and Samson,

Thanks so much for your responses! I am not a programmer and therefore not
conversant in Java, so I apologize in advance for my superficial
understanding of resources you provided.

I have been creating my survey using the XLSform and submitting it for XML
conversion on the ODK website.

I tried using your decimal-date-time function on the XLSform. It was
accepted without error on the ODK website, but when I tested the constraint
on the enketo preview I received the following error.

A formula evaluation error occurred. Please contactsupport@enketo.orgwith this error:
• Error occurred trying to evaluate: . >
date(decimal-date-time(today()) - (6060243651000)), message: Function
"{}decimal-date-time" does not exist.

I understand that that new functionality may not be used on the enketo
version.

Since it sounds like doing date arithmetic can be complex and imprecise,
are there other suggested functions for bounding dates dynamically? I am
not wedded to doing arithmetic on a date converted to an integer; it was
simply only tool I could think of in my somewhat limited toolbox.

Many thanks for your assistance!

Regards,

Caitlin

On Sunday, 1 December 2013 15:00:36 UTC-5, caitlin...@gmail.com wrote:

Good Afternoon,

I am having difficulty understanding how a date is stored and therefore
placing a constraint around a date. I am asking the survey team to enter
the date of the last dose of Vitamin A from the respondent's vaccine card;
however I only want to document use within a year from the survey date.

I have tried converting my date to an integer and performing an
operation assuming that int converted the date to a timestamp in seconds.

. > date(int(today()) - (606024*365))

I have tried using milliseconds.

. > date(int(today()) - (6060243651000))

Any thoughts would be greatly appreciated!

Many thanks in advance.

Regards,

Caitlin

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Those 2 functions are not yet supported in Enketo, though they will be
eventually (I hadn't heard about them until yesterday).

Note: the same XPath functions that ODK Collect supports are normally
supported in Enketo (just running behind on a few newer functions). Nothing
beyond this. No javascript and no plans to deviate from the functions
supported in ODK Collect unless agreeing with the ODK dev team first. I
think it's quite important we keep these two clients compatible for our
users.

··· On Tuesday, December 3, 2013 10:13:56 AM UTC-7, Mitch wrote: > > If you are targeting Enketo, then there should be a way to directly use > Javascript functions for dates (I hope), rather than be restricted to just > the functionality that is available in ODK Collect. However, I am not > familiar enough with Enketo to provide guidance on that. > > > On Mon, Dec 2, 2013 at 8:59 PM, <caitlin...@gmail.com >wrote: > >> Hi Mitch and Samson, >> >> Thanks so much for your responses! I am not a programmer and therefore >> not conversant in Java, so I apologize in advance for my superficial >> understanding of resources you provided. >> >> I have been creating my survey using the XLSform and submitting it for >> XML conversion on the ODK website. >> >> I tried using your decimal-date-time function on the XLSform. It was >> accepted without error on the ODK website, but when I tested the constraint >> on the enketo preview I received the following error. >> >> A formula evaluation error occurred. Please contact...@enketo.orgwith this error: >> • Error occurred trying to evaluate: . > >> date(decimal-date-time(today()) - (60*60*24*365*1000)), message: Function >> "{}decimal-date-time" does not exist. >> >> I understand that that new functionality may not be used on the enketo >> version. >> >> Since it sounds like doing date arithmetic can be complex and imprecise, >> are there other suggested functions for bounding dates dynamically? I am >> not wedded to doing arithmetic on a date converted to an integer; it was >> simply only tool I could think of in my somewhat limited toolbox. >> >> Many thanks for your assistance! >> >> Regards, >> >> Caitlin >> >> >> >> >> On Sunday, 1 December 2013 15:00:36 UTC-5, caitlin...@gmail.com wrote: >> > Good Afternoon, >> > >> > I am having difficulty understanding how a date is stored and therefore >> placing a constraint around a date. I am asking the survey team to enter >> the date of the last dose of Vitamin A from the respondent's vaccine card; >> however I only want to document use within a year from the survey date. >> > >> > I have tried converting my date to an integer and performing an >> operation assuming that int converted the date to a timestamp in seconds. >> > >> > . > date(int(today()) - (60*60*24*365)) >> > >> > I have tried using milliseconds. >> > >> > . > date(int(today()) - (60*60*24*365*1000)) >> > >> > Any thoughts would be greatly appreciated! >> > >> > Many thanks in advance. >> > >> > Regards, >> > >> > Caitlin >> >> -- >> You received this message because you are subscribed to the Google Groups >> "ODK Developers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to opendatakit-developers+unsubscribe@googlegroups.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitche...@gmail.com >