Author Topic: [HELP] Date does not appear in the layout  (Read 67 times)

arthurvalenca

  • Full Member
  • ***
  • Posts: 25
    • View Profile
[HELP] Date does not appear in the layout
« on: September 14, 2018, 03:23:44 PM »
Hello everyone, I am having difficulty with this code I would like the date to appear in layout but it does not work, I tried with another way it appears but the month is delayed, instead of being month 09, it is 08, I would like it to look at the names and present the names according to the code, can anyone help?

Code: [Select]
//Date
local dt = fe.add_text( "", ::flw * 0.350,::flh * 0.360,::flw * 0.411,::flh * 0.032 );
function update_date( ttime )

local days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
local months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

{
local now = date();
dt.msg = ("%s", days[now.wday]) + "/" + ("%s", months[now.month]) + "/" + ("%02d", now.day ) + "/" + ("%04d", now.year );
}
fe.add_ticks_callback( this, "update_date" );

PS:
This code appears below but it does not work very well, it is not in the correct format:



Code: [Select]
//Date
local dt = fe.add_text( "", ::flw * 0.350,::flh * 0.360,::flw * 0.411,::flh * 0.032 );
function update_date( ttime )

{
local now = date();
dt.msg = ("%s", now.wday) + "/" + ("%s", now.month) + "/" + ("%02d", now.day ) + "/" + ("%04d", now.year );
}
fe.add_ticks_callback( this, "update_date" );

Help Please.


keilmillerjr

  • Hero Member
  • *****
  • Posts: 554
    • View Profile
Re: [HELP] Date does not appear in the layout
« Reply #1 on: September 14, 2018, 05:36:13 PM »
now.month returns a value 0-11, perfect for indexing an array.

I suggest starting simple. Comment out the function and object. Create an instance of the now class. Print to console the month. If value checks out, create your month array with string values, and print array with now.month as the index. Does it work?

I am super exhausted. Will check back with you tomorrow afternoon and help troubleshoot if your still having issues.

arthurvalenca

  • Full Member
  • ***
  • Posts: 25
    • View Profile
Re: [HELP] Date does not appear in the layout
« Reply #2 on: September 14, 2018, 05:56:34 PM »
now.month returns a value 0-11, perfect for indexing an array.

I suggest starting simple. Comment out the function and object. Create an instance of the now class. Print to console the month. If value checks out, create your month array with string values, and print array with now.month as the index. Does it work?

I am super exhausted. Will check back with you tomorrow afternoon and help troubleshoot if your still having issues.

Thanks for the help, I'll try something else here.

keilmillerjr

  • Hero Member
  • *****
  • Posts: 554
    • View Profile
Re: [HELP] Date does not appear in the layout
« Reply #3 on: September 14, 2018, 06:43:00 PM »
Couldn’t sleep. Fully working and tested example. I choose to go with magic function because it’s only called on signal. It might make things speedier not being called every tick. Shouldn’t need to update in real time I would think, unless displaying hours/min/sec.

Code: [Select]
// Date
function updateTimestamp() {
  local days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  local months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  local now = date();
  return now.day + "/" + months[now.month] + "/" + now.year;
}
local timestamp = fe.add_text("[!updateTimestamp]", 0, 0, fe.layout.width, fe.layout.height/20);
« Last Edit: September 14, 2018, 06:45:08 PM by keilmillerjr »

arthurvalenca

  • Full Member
  • ***
  • Posts: 25
    • View Profile
Re: [HELP] Date does not appear in the layout
« Reply #4 on: September 15, 2018, 12:13:09 PM »
Couldn’t sleep. Fully working and tested example. I choose to go with magic function because it’s only called on signal. It might make things speedier not being called every tick. Shouldn’t need to update in real time I would think, unless displaying hours/min/sec.

Code: [Select]
// Date
function updateTimestamp() {
  local days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  local months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  local now = date();
  return now.day + "/" + months[now.month] + "/" + now.year;
}
local timestamp = fe.add_text("[!updateTimestamp]", 0, 0, fe.layout.width, fe.layout.height/20);

 :) :) :) :) :) :)keilmillerjr friend thank you very much your code worked perfectly in my layout, it was this result that I was wanting to get, great thank you for your support your codes are excellent.