Discussion:
Day number
Jim Wagner
2016-08-26 04:58:10 UTC
Permalink
Greetings, NUG -

I have a rather large set of data from a third party (US Forest Service and a major university). It is meteorological data taken at 30 minute intervals for a whole year and I have several of these to analyze. It is csv data and each record (line) begins with a year field (eg, 2015 - thats fine), a month field (eg, 1 to 12 - thats fine), then a day field which is the day number within the year (1 to 365 or 366 - thats NOT fine).

I am trying to turn this into a date object but the “Day of year” property of a date object is read-only.

I have to do this conversion for every line in the file, so execution time IS important.

Does anyone have a suggestion about how to handle this? ParseDate() does not seem helpful, here.

Many thanks
Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home



_______________________________________________
Unsubscribe by sending a message to:
<nug-leave
Markus Winter
2016-08-26 05:09:36 UTC
Permalink
Day of year is calculated automatically so nothing for you to do. Just set the date and you already have DayOfYear.

Take care

MfG

Markus

Sent from my iPad


_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Jim Wagner
2016-08-26 05:19:50 UTC
Permalink
Markus -

Perehaps I did not explain it very well?

I have no day of month! The three pieces of data in the file are year, month, and day of year. I need ti converted those three data values into a date object.

Thanks
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by Markus Winter
Day of year is calculated automatically so nothing for you to do. Just set the date and you already have DayOfYear.
Take care
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
vaughnsc .
2016-08-26 05:22:35 UTC
Permalink
Set a date object to 1/1/year (midnight) then add dayofyear*86400 to the
totalseconds

Cheers

Vaughn
Post by Markus Winter
Day of year is calculated automatically so nothing for you to do. Just set
the date and you already have DayOfYear.
Take care
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Jim Wagner
2016-08-26 05:28:51 UTC
Permalink
Wow, Vaughn! Two in a row! That is the winner.

Many, many thanks.

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by vaughnsc .
Set a date object to 1/1/year (midnight) then add dayofyear*86400 to the
totalseconds
Cheers
Vaughn
Post by Markus Winter
Day of year is calculated automatically so nothing for you to do. Just set
the date and you already have DayOfYear.
Take care
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Markus Winter
2016-08-26 06:24:56 UTC
Permalink
Post by vaughnsc .
Set a date object to 1/1/year (midnight) then add dayofyear*86400 to the
totalseconds
Assuming the first of Jan is day 1, should that not be dayofyear*86400 - 1000

(Could subtract any value between 1 and 86399)

MfG

Markus

Sent from my iPad
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Support
2016-08-26 06:36:09 UTC
Permalink
Good catch Markus! Adding 1*86400 to January 1st would indeed yield January 2.

You could:
a) first subtract a second from new date(year,1,1) totalseconds, but
b) use (dayofyear-1)*86400 is cleaner IMO

Cheers,

Vaughn
Post by Markus Winter
Post by vaughnsc .
Set a date object to 1/1/year (midnight) then add dayofyear*86400 to the
totalseconds
Assuming the first of Jan is day 1, should that not be dayofyear*86400 - 1000
(Could subtract any value between 1 and 86399)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Jim Wagner
2016-08-26 06:45:15 UTC
Permalink
Just discovered that. They number January 1 as “Day of year” = 1 so you have to subtract 1 from that. Other than that, spot on!

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by Support
Good catch Markus! Adding 1*86400 to January 1st would indeed yield January 2.
a) first subtract a second from new date(year,1,1) totalseconds, but
b) use (dayofyear-1)*86400 is cleaner IMO
Cheers,
Vaughn
Post by Markus Winter
Post by vaughnsc .
Set a date object to 1/1/year (midnight) then add dayofyear*86400 to the
totalseconds
Assuming the first of Jan is day 1, should that not be dayofyear*86400 - 1000
(Could subtract any value between 1 and 86399)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

Lis
Markus Winter
2016-08-26 06:55:42 UTC
Permalink
To optimize you could also simply do

dayofyear*86399

With 366 days a year the time varies from 23:59:59 down to 23:52:54 but the date is correct

Or use 86390 if you don't want to cut it so close ;-)

MfG

Markus

Sent from my iPad


_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
V S Cordero
2016-08-26 07:10:27 UTC
Permalink
Devil’s advocate: That would be fine if the time is never relevant.

I’d prefer to keep the code viable for some future case where time matters as well, with a dayofyear conversion that doesn’t skew any initial hh:mm:ss supplied.

In other words, I could see me many multiples of 86399 seconds from now scratching my head, when I've long forgotten that dandy shortcut :)

Cheers

Vaughn
Post by Markus Winter
To optimize you could also simply do
dayofyear*86399
With 366 days a year the time varies from 23:59:59 down to 23:52:54 but the date is correct
Or use 86390 if you don't want to cut it so close ;-)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <listhel
Markus Winter
2016-08-26 07:53:02 UTC
Permalink
Post by V S Cordero
I’d prefer to keep the code viable for some future case where time matters as well, with a dayofyear conversion that doesn’t skew any initial hh:mm:ss supplied.
When the time matters then you could set it from whatever info is available.

Butyes, this is not a general method, just an optimized use scenario.
Post by V S Cordero
In other words, I could see me many multiples of 86399 seconds from now scratching my head, when I've long forgotten that dandy shortcut :)
That's what comments are for ;-)

MfG

Markus

Sent from my iPad


_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lis
Gerd Wilmer
2016-08-26 08:54:23 UTC
Permalink
Hi guys

has anyone considered leap years?
Before you start to analyse a year, check whether the first "day" in March is 59
If it is 60 then you have a leap year.


Also, from the Language Reference:
ParseDate does not parse the Time value of a date, if present.

Cheers

Gerd
Post by Markus Winter
Post by V S Cordero
I’d prefer to keep the code viable for some future case where time matters as well, with a dayofyear conversion that doesn’t skew any initial hh:mm:ss supplied.
When the time matters then you could set it from whatever info is available.
Butyes, this is not a general method, just an optimized use scenario.
Post by V S Cordero
In other words, I could see me many multiples of 86399 seconds from now scratching my head, when I've long forgotten that dandy shortcut :)
That's what comments are for ;-)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
V S Cordero
2016-08-26 10:37:44 UTC
Permalink
In this case both the dayOfYear and year are provided, and should be 'treated as gospel.’

But if you really want to 'go there':

dim year as integer=1898 //test: 1600 was a leap year, 1700 was not
dim isLeap as Boolean=(year mod 4=0 and (year mod 100<>0 or year mod 400=0))

Vaughn
Post by Gerd Wilmer
Hi guys
has anyone considered leap years?
Before you start to analyse a year, check whether the first "day" in March is 59
If it is 60 then you have a leap year.
ParseDate does not parse the Time value of a date, if present.
Cheers
Gerd
Post by Markus Winter
Post by V S Cordero
I’d prefer to keep the code viable for some future case where time matters as well, with a dayofyear conversion that doesn’t skew any initial hh:mm:ss supplied.
When the time matters then you could set it from whatever info is available.
Butyes, this is not a general method, just an optimized use scenario.
Post by V S Cordero
In other words, I could see me many multiples of 86399 seconds from now scratching my head, when I've long forgotten that dandy shortcut :)
That's what comments are for ;-)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-leave@
Gerd Wilmer
2016-08-26 12:16:57 UTC
Permalink
Except: (quoted from Wikipedia)

Over a period of 4 centuries, the accumulated error of adding a leap day every 4 years amounts to about 3 extra days.
The Gregorian calendar therefore removes three leap days every 400 years, which is the length of its leap cycle.
This is done by removing February 29 in the three century years (multiples of 100) that cannot be exactly divided by 400.[6][7]
The years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are common years.
By this rule, the average number of days per year is 365 + 1⁄4 − 1⁄100 + 1⁄400 = 365.2425.[8]


Cheers

Gerd
Post by V S Cordero
In this case both the dayOfYear and year are provided, and should be 'treated as gospel.’
dim year as integer=1898 //test: 1600 was a leap year, 1700 was not
dim isLeap as Boolean=(year mod 4=0 and (year mod 100<>0 or year mod 400=0))
Vaughn
Post by Gerd Wilmer
Hi guys
has anyone considered leap years?
Before you start to analyse a year, check whether the first "day" in March is 59
If it is 60 then you have a leap year.
ParseDate does not parse the Time value of a date, if present.
Cheers
Gerd
Post by Markus Winter
Post by V S Cordero
I’d prefer to keep the code viable for some future case where time matters as well, with a dayofyear conversion that doesn’t skew any initial hh:mm:ss supplied.
When the time matters then you could set it from whatever info is available.
Butyes, this is not a general method, just an optimized use scenario.
Post by V S Cordero
In other words, I could see me many multiples of 86399 seconds from now scratching my head, when I've long forgotten that dandy shortcut :)
That's what comments are for ;-)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.c
Markus Winter
2016-08-26 12:21:58 UTC
Permalink
Post by Gerd Wilmer
By this rule, the average number of days per year is 365 + 1⁄4 − 1⁄100 + 1⁄400 = 365.2425
Which helps with the problem at hand how …?


_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xo
Gerd Wilmer
2016-08-26 19:47:17 UTC
Permalink
If you want to get an accurate date from day of the year past 28 Feb
you need to know whether this is a leap year.
If you don't, then all dates past 28 Feb will be inaccurate in a leap year
Post by Markus Winter
Post by Gerd Wilmer
By this rule, the average number of days per year is 365 + 1⁄4 − 1⁄100 + 1⁄400 = 365.2425
Which helps with the problem at hand how …?
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@li
Markus Winter
2016-08-26 20:11:10 UTC
Permalink
Post by Gerd Wilmer
If you want to get an accurate date from day of the year past 28 Feb
you need to know whether this is a leap year.
If you don't, then all dates past 28 Feb will be inaccurate in a leap year
I think you misunderstand how the date object works.

All you need to do is to instantiate a new date with the 1st of January of that year, and then add the number of days. YOU don't have to take care of leap years, the date object will do it for you.

MfG

Markus

Sent from my iPad


_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Jim Wagner
2016-08-26 21:32:14 UTC
Permalink
YES! Leap year is built in and so are those exceptions to leap year, like year 2000 was.

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by Markus Winter
Post by Gerd Wilmer
If you want to get an accurate date from day of the year past 28 Feb
you need to know whether this is a leap year.
If you don't, then all dates past 28 Feb will be inaccurate in a leap year
I think you misunderstand how the date object works.
All you need to do is to instantiate a new date with the 1st of January of that year, and then add the number of days. YOU don't have to take care of leap years, the date object will do it for you.
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Markus Winter
2016-08-26 11:42:50 UTC
Permalink
Post by Gerd Wilmer
has anyone considered leap years?
Yes. Not a problem.
Post by Gerd Wilmer
Before you start to analyse a year, check whether the first "day" in March is 59
If it is 60 then you have a leap year.
Not necessary
Post by Gerd Wilmer
ParseDate does not parse the Time value of a date, if present.
Not necessary either.

:-)
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
emile.a.schwarz
2016-08-26 13:31:17 UTC
Permalink
Gerd:

 

I love your creative way to know if the year have a February 29th !!!

 

Remarkable !

 

Emile

 
Message du 26/08/16 10:55
De : "Gerd Wilmer"
A : "Nug"
Objet : Re: Day number
Hi guys
has anyone considered leap years?
Before you start to analyse a year, check whether the first "day" in March is 59
If it is 60 then you have a leap year.
ParseDate does not parse the Time value of a date, if present.
Cheers
Gerd
Post by Markus Winter
Post by V S Cordero
I’d prefer to keep the code viable for some future case where time matters as well, with a dayofyear conversion that doesn’t skew any initial hh:mm:ss supplied.
When the time matters then you could set it from whatever info is available.
Butyes, this is not a general method, just an optimized use scenario.
Post by V S Cordero
In other words, I could see me many multiples of 86399 seconds from now scratching my head, when I've long forgotten that dandy shortcut :)
That's what comments are for ;-)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <li
Emile Schwarz
2016-08-26 11:40:57 UTC
Permalink
Hi Vaughn,
can you do something about the mail address name you use ?
Think: "Gee, I receive a mail from support !"
Hi UNKNOW,
WHY DO YOU FLAG Markus Winter MAILS AS SPAM ?
Emile

De : Support <***@mobilesyncbrowser.com>
À : Nug <***@lists.xojo.com>
Envoyé le : Vendredi 26 août 2016 8h36
Objet : Re: Day number

Good catch Markus! Adding 1*86400 to January 1st would indeed yield January 2.

You could:
a) first subtract a second from new date(year,1,1) totalseconds, but
b) use (dayofyear-1)*86400 is cleaner IMO

Cheers,

Vaughn
Post by Markus Winter
Post by vaughnsc .
Set a date object to 1/1/year (midnight) then add dayofyear*86400 to the
totalseconds
Assuming the first of Jan is day 1, should that not be dayofyear*86400 - 1000
(Could subtract any value between 1 and 86399)
MfG
Markus
Sent from my iPad
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>



_______________________________________________
Unsubscribe by sending a message to:
<nug-***@l
Claudius Sailer
2016-08-26 05:23:07 UTC
Permalink
How you calculate the day?

I would create the first of the month, check which dayoftheyear you get and ad the difference to your dayoftheyear to your date.

I know three steps, but at the moment I don't have an other idea.

Claudius
Post by Jim Wagner
Greetings, NUG -
I have a rather large set of data from a third party (US Forest Service and a major university). It is meteorological data taken at 30 minute intervals for a whole year and I have several of these to analyze. It is csv data and each record (line) begins with a year field (eg, 2015 - thats fine), a month field (eg, 1 to 12 - thats fine), then a day field which is the day number within the year (1 to 365 or 366 - thats NOT fine).
I am trying to turn this into a date object but the “Day of year” property of a date object is read-only.
I have to do this conversion for every line in the file, so execution time IS important.
Does anyone have a suggestion about how to handle this? ParseDate() does not seem helpful, here.
Many thanks
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.
Metsis
2016-08-29 08:05:09 UTC
Permalink
Normal warnings about being late and dense apply...

Write a conversion application that
- reads in year, month and day-of-year of a line in the CSV file
- if a previously unaccounted year is met
- create a Date object for all days of that year
- save year + day-of-year from those Date object as keys and
day-of-month as values in a dictionary for fast lookup
- replace that day-of-year with day-of-month in the file by using that
dictionary

You can have this conversion application crunch all CSV files during the
night(s). Now your real application doesn't neet to worry about the
dates and should you need to alter something, you have the data already
converted.

Just my...

Juha Metsäkallas



_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo
Joe Huber
2017-03-16 16:28:08 UTC
Permalink
Create a date with the known year (also include the Time fields if need be, but keep the Month and Day fields empty)
Multiply the known Day of Year times the number of seconds in a day (24x60x60)
Add that value to the TotalSeconds property of the date you created in the first step.
Now you have a Xojo date object set to your specific date and time
Post by Jim Wagner
Greetings, NUG -
I have a rather large set of data from a third party (US Forest Service and a major university). It is meteorological data taken at 30 minute intervals for a whole year and I have several of these to analyze. It is csv data and each record (line) begins with a year field (eg, 2015 - thats fine), a month field (eg, 1 to 12 - thats fine), then a day field which is the day number within the year (1 to 365 or 366 - thats NOT fine).
I am trying to turn this into a date object but the “Day of year” property of a date object is read-only.
I have to do this conversion for every line in the file, so execution time IS important.
Does anyone have a suggestion about how to handle this? ParseDate() does not seem helpful, here.
Many thanks
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
__________________________________________

Loading...