Skip to content
How to map Year and...
 
Notifications
Clear all

[Solved] How to map Year and Day_of_year to actual date

3 Posts
3 Users
0 Reactions
2,131 Views
Avatar
Posts: 3
Customer
Topic starter
(@xlptf79tizl550gfep8lo6isp6t2)
Active Member
Joined: 3 years ago

I have a time index consisting of actual dates:

Time := Sequence( start_date, end_date )

The start_date and end_date aren't on even year or even month boundaries.

I also have a 2-D representation of data across time that uses these two indexes:

Index Year := 2019 .. 2021

Index Date_of_year := ['1-Jan', '2-Jan', ..., '31-Dec' ]

BTW, my actual definitions for these are:

Index Year := Unique(DatePart(Time,'Y'))

Index Date_of_year := Local d := Sequence(1-Jan-2020,31-Dec-2020) Do DatePart(d,'D') & '-' & DatePart(d,'EEE')

 

Note that Date_of_year includes '29-Feb', even though non-leap years don't have data for that date (my arrays have Null in that case). 

I want to compute a map from the 2-D Year x Date_of_year to the 1-D Time. In other words, the map would be a 2-D array, indexed by Year and Date_of_year, and each cell of that array would be the corresponding full date as it appears in the Time index. Some cells won't be valid dates (like 29-Feb-2021) and some will be outside by Time range since my Time index doesn't start on even year boundaries. Ideally those cells would be Null. 

So, for example, the cell at [ Year = 2021, Date_of_year = '23-Jul' ] would be the date 23-July-2021.

The attached file sets up the problem -- I need the definition for Y_and_D_to_Time.

2 Replies
Lonnie Chrisman
Posts: 42
Admin
(@lchrisman)
Member
Joined: 14 years ago
Local d := ParseDate(Day_of_year&"-"&Year);
d := if Day_of_year='29-Feb' and DatePart(d,'D')<>29 then null else d;
Time[Time=d,defVal:null]

Second line sets 29-Feb to Null for the non-leap years.  The last line sets all cells in the map to Null if they don't exist in your Time index. In terms of using this as a mapping, you wouldn't need to do that last step (although it doesn't hurt), so this would be sufficient:

Local d := ParseDate(Day_of_year&"-"&Year);
if Day_of_year='29-Feb' and DatePart(d,'D')<>29 then null else d

Either case should work fine to expand a 1-D array, x, that is indexed by Time to a 2-D array using

x[ Time = Y_and_D_to_Time ]

 

Reply
Avatar
Posts: 10
Customer
(@patstevens)
Eminent Member
Joined: 3 years ago
Local isLeap := Mod(Year,4)=0 and Mod(Year,100)<>0 or Mod(Year,400)=1;
Local offset := 
	if Day_of_year='29-Feb' and not isLeap then null 
	else if @Day_of_year > @[Day_of_year='29-Feb'] and not isLeap then @Day_of_year-2 
	else @Day_of_year-1;

MakeDate(Year,1,1) + offset
Reply
Share:

Download the free edition of Analytica

The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


    Analytica Cubes Pattern

    Download the free edition of Analytica

    The free version of Analytica lets you create and edit models with up to 101 variables, which is pretty substantial since each variable can be a multidimensional array. It also lets you run larger modes in ‘browse mode.’ Learn more about the free edition.

    While Analytica doesn’t run on macOS, it does work with Parallels or VMWare through Windows.


      Analytica Cubes Pattern