Trickstar
  • Posts: 26
  • Joined: 02/07/2012
Well I have written a JavaScript code that dynamically updates a clock to the millisecond that the page was loaded and I have integrated it into other ASP.Net applications before. Now since YAF already has its own clock that corrects the time zones, I tried to write a JavaScript code (below) to access it since I couldn't find the source file containing the "Current Time", the closest I came was in forum.ascx but it didn't quite have what I was looking for.

This function I called on the bottom of the page with "forum_ctl03_Welcome_TimeNow" as the ID and the millisecond ASP method for milliseconds:
function setClockYAF(elementId, milliseconds) {
    var element = documnet.getElementById(elementId);
	var content = element.innerHTML;
	var array[];
	var amPm;
	var endValue;
	if (content.search("AM") != -1) {
	    endValue = content.search("AM") + 1;
		amPm = "AM";
	}
	if (content.search("PM") != -1) {
		    endValue = content.search("PM") + 1;
			amPm = "PM";
	}
	var startValue = content.search(": ") + 2;
	var time = content.substring(startValue, endValue);
    	array = time.split(":");
	array[2] = array[2].replace(" " + amPm, "");
	content.replace(time, "<span id=\"setClockYAF\"></span>");
	var clockYAF = new Clock("setClockYAF", array[0], array[1], array[2], milliseconds);
	clockYAF.update = true;
        clockYAF.display();
}


The Clock object is my own dynamic clock. Anyways, the above method didn't work and is more work than I should have to put into it. So my question is, what file contains the time displayed where the forums says "Current Time: hh:mm:ss"?
Sponsor
tha_watcha
  • Posts: 4071
  • Joined: 06/03/2010
It is generated in the ../controls/ForumWelcome.ascx

<div id="divTimeNow">
        <asp:Label ID="TimeNow" runat="server" />
    </div>

UserPostedImage
tha_watcha
  • Posts: 4071
  • Joined: 06/03/2010
Simply use

<% Response.Write(DateTime.UtcNow.Hour.ToString()); %>
UserPostedImage
Trickstar
  • Posts: 26
  • Joined: 02/07/2012
Thats what I'm currently using but it just gives me the time from the server instead of the time set in Admin Control Panel of the forum. Is there a way to check which timezone was selected? Right now I'm using the following to return the time I want, but if a user is from another timezone and changes their settings, it will still display the time from the timezone I programmed. I want the hour to change with the user timezone settings for each specific user and if I change the timezone in Admin CP.

Code (in a client-side script tag):
                            <%  var hour = DateTime.UtcNow.Hour;
                                if (hour < 5) {
                                    hour += 19;
                                }
                                else {
                                    hour -= 5;
                                }
                            %>
                            if (document.getElementById("clock")!= undefined) { 
                                var clock = new Clock("clock", <% Response.Write(hour.ToString()); %>, <% Response.Write(DateTime.UtcNow.Minute.ToString()); %>, <% Response.Write(DateTime.UtcNow.Second.ToString()); %>, <% Response.Write(DateTime.UtcNow.Millisecond.ToString()); %>);
                                clock.update = true;
                                clock.display();

Trickstar
  • Posts: 26
  • Joined: 02/07/2012
Sorry for the bump but I need to know if theres a variable that contains what Time Zone the registered user is in? Just as theres one that tells you what theme is selected (below).

<% if (YafContext.Current.Get<ITheme>().ThemeFile == "default.xml") {
%>


EDIT:
The following works pretty well, but now I just need to be able to check for daylight savings time and its pretty hard since AccountForDST() is set to private so I'm trying to figure out a way to take the code to that function and use it for what I'm looking for. This is what I have so far:

<% var hour = DateTime.UtcNow.Hour + (YafContext.Current.TimeZoneUser / 60);
            if (YafContext.Current.DSTUser)
            {
                if (TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").IsDaylightSavingTime(DateTime.UtcNow + YAF.Core.Services.YafDateTime.TimeOffset))
                {
                    hours += 1;
                }
            } %>


I get a compilation error because I can't use TimeOffset in this context and by looking at YafDateTime I can't really figure out how its used because its always used as "this.TimeOffset"
tha_watcha
  • Posts: 4071
  • Joined: 06/03/2010
Quote:

get a compilation error because I can't use TimeOffset in this context and by looking at YafDateTime I can't really figure out how its used because its always used as "this.TimeOffset"



use the interface IDateTime instead of YafDateTime
Replace it with...

<% var hour = DateTime.UtcNow.Hour + (YafContext.Current.TimeZoneUser / 60);
if (YafContext.Current.DSTUser)
{
if (TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").IsDaylightSavingTime(DateTime.UtcNow + YAF.Core.Services.YafDateTime.TimeOffset))
{
hours += 1;
}
}var hour = DateTime.UtcNow.Hour + (YafContext.Current.TimeZoneUser / 60);
if (YafContext.Current.DSTUser)
{
if (TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").IsDaylightSavingTime(DateTime.UtcNow + YafContext.Current.Get<IDateTime>().TimeOffset))
{
hours += 1;
}
} %>

By the Way can i recommend a better solution to create a Ticking Clock. I use this little jquery plugin

http://www.tcpweb.com.br/JS-Clock/ 

example

<span id="clock">Error getting time</span>


js sample code...

$(document).ready(function(){
			$('#clock').jsclock('<%# YafContext.Current.Get<IDateTime>().FormatTime(DateTime.UtcNow) %>')
		});


and of course you need to load the jquery plugin js file.



UserPostedImage
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved