<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Javascript</title>
	<atom:link href="https://khalil232.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://khalil232.com</link>
	<description></description>
	<lastBuildDate>Tue, 14 Apr 2026 20:16:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://i0.wp.com/khalil232.com/wp-content/uploads/2023/12/khalil232-favicon-color.png?fit=32%2C32&#038;ssl=1</url>
	<title>Javascript</title>
	<link>https://khalil232.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">222554886</site>	<item>
		<title>Building User-Friendly Web Apps</title>
		<link>https://khalil232.com/vbcs-tutorials/298/how-to-build-user-friendly-web-apps/</link>
		
		<dc:creator><![CDATA[khalil]]></dc:creator>
		<pubDate>Mon, 18 Nov 2024 16:15:31 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[VBCS-Tutorials]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[VBCS]]></category>
		<guid isPermaLink="false">https://khalil232.com/?p=298</guid>

					<description><![CDATA[Building a user-friendly web app isn’t just about features. Learn practical UX improvements like better navigation, non-blocking interactions, and clear visual cues that make your app easier to use.]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-jetpack-markdown"><p>Building a web app isn’t just about features. It’s about how users interact with it. A good app should feel natural, predictable, and easy to use. Small usability improvements often make a big difference in how people experience your product.</p>
<hr>
<h2>Navigation Enhancements</h2>
<h3>Make Pages Easy to Bookmark</h3>
<p>Update the URL to reflect the current state when users search, filter, or view specific content. This allows them to return to the same place without repeating steps.</p>
<ul>
<li>
<p><strong>Example:</strong></p>
<ul>
<li>Before: User searches for “Vehicle XYZ”</li>
<li>After: <code>khalil232.com/someapp/search?query=Vehicle+XYZ</code></li>
</ul>
</li>
</ul>
<p>This saves time and makes your app feel more reliable.</p>
<h3>Support Deep Linking</h3>
<p>Allow users to open specific records, sections, or screens directly using a URL. This avoids repetitive navigation.</p>
<ul>
<li>
<p><strong>Example:</strong></p>
<ul>
<li><code>khalil232.com/someapp/vehicle/12345</code></li>
</ul>
</li>
</ul>
<p>Deep linking is especially useful in business apps where users frequently revisit or share specific records.</p>
<h2>Respect User Actions</h2>
<h3>Avoid Restricting Basic Functionalities</h3>
<p>Do not block basic browser actions like cut, copy, or paste. Users expect these to work everywhere.</p>
<ul>
<li>
<p><strong>Avoid:</strong></p>
<ul>
<li>Disabling right-click</li>
<li>Preventing text selection</li>
</ul>
</li>
</ul>
<p>Blocking these actions creates frustration and breaks normal user behavior.</p>
<h2>Non-Blocking Processes</h2>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/khalil232.com/wp-content/uploads/2024/11/do-dont-blocking-ui.png?ssl=1" alt="Do vs Don't blocking ui example"></p>
<h3>Reduce Blocking Actions</h3>
<p>Full-screen loaders and blocking overlays interrupt users and slow them down. Instead, allow them to continue working.</p>
<ul>
<li>
<p><strong>Better approaches:</strong></p>
<ul>
<li>Run tasks in the background</li>
<li>Keep screens interactive</li>
<li>Show completion using notifications or toasts</li>
</ul>
</li>
</ul>
<h4>Example</h4>
<p>While generating a report, let users continue using the app. Notify them when the report is ready to download.</p>
<p>This keeps the app responsive and efficient.</p>
<h2>Visual Clarity</h2>
<h3>Make Links Visually Distinct</h3>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/khalil232.com/wp-content/uploads/2024/11/do-dont-link-image.png?ssl=1" alt="Do vs Don't link example"></p>
<p>Links should clearly look clickable. Use color, underline, or icons to differentiate them from normal text.</p>
<ul>
<li>
<p><strong>Example:</strong></p>
<ul>
<li>Blue, underlined text for links</li>
</ul>
</li>
</ul>
<p>Clear visual cues improve navigation and reduce confusion.</p>
<h3>Confirm Difficult Actions</h3>
<p>Always confirm actions that cannot be undone, such as deleting data.</p>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/khalil232.com/wp-content/uploads/2024/11/delete-confirmation.png?ssl=1" alt="Delete popup example"></p>
<ul>
<li>
<p><strong>Example:</strong></p>
<ul>
<li>“This action will permanently delete your record. Do you want to continue?”</li>
</ul>
</li>
</ul>
<p>This prevents mistakes and gives users confidence.</p>
<h2>Data Management</h2>
<h3>Manage Text Length in Tables or Lists</h3>
<p>Long text can break layouts and reduce readability. Handle it properly.</p>
<ul>
<li>
<p><strong>Recommended:</strong></p>
<ul>
<li>Truncate long text</li>
<li>Add “Read More” options</li>
<li>Use tooltips or modals for full content</li>
</ul>
</li>
</ul>
<p>This keeps the UI clean without hiding important information.</p>
<hr>
<h3>File Upload Previews</h3>
<p><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/khalil232.com/wp-content/uploads/2024/11/File-upload-do-dont.png?ssl=1" alt="Do vs Don't File Upload example"></p>
<p>Show a preview before users submit uploaded files. Include key details.</p>
<ul>
<li>
<p><strong>Display:</strong></p>
<ul>
<li>File name</li>
<li>File size</li>
<li>File type</li>
</ul>
</li>
</ul>
<p>Users should be able to remove or replace files easily before submitting.</p>
<h2>Conclusion</h2>
<p>User-friendly apps are built through small, thoughtful decisions.</p>
<p>Making navigation easier, avoiding unnecessary restrictions, and keeping the interface responsive all contribute to a better experience. These improvements may seem minor, but they significantly reduce user frustration and make your app more enjoyable to use.</p>
</div>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">298</post-id>	</item>
		<item>
		<title>Make VBCS application migration easier</title>
		<link>https://khalil232.com/vbcs-tutorials/282/make-vbcs-application-migration-easier/</link>
		
		<dc:creator><![CDATA[khalil]]></dc:creator>
		<pubDate>Fri, 02 Aug 2024 18:32:38 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[VBCS-Tutorials]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[VBCS]]></category>
		<guid isPermaLink="false">https://khalil232.com/?p=282</guid>

					<description><![CDATA[These are some general tips for a VBCS developer to make changes in VBCS application before migrating to different instances. Use connections based on backend. Instead of directly using a URL, This way, when we migrate from one instance to another, we can make changes in backend URL and credentials. This will be one-time setup [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>These are some general tips for a VBCS developer to make changes in VBCS application before migrating to different instances. </p>



<h2 class="wp-block-heading has-medium-font-size">Use connections based on backend. Instead of directly using a URL,</h2>



<p class="has-small-font-size">This way, when we migrate from one instance to another, we can make changes in backend URL and credentials. This will be one-time setup when me get a new instance and at code level, we don&#8217;t have to make many changes </p>



<p class="has-medium-font-size">Get Application URL using JS function </p>



<p class="has-small-font-size">For any kind of link to different VBCS application, use JavaScript code to get application URL using </p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>$application.path
// design url -- {{vbcs-cloud-url}}/ic/builder/design/khalil/1.0.0/preview/webApps/demo/
// live url -- {{vbcs-cloud-url}}/ic/builder/rt/khalil/live/webApps/demo/ </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #9CDCFE">$application</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">path</span></span>
<span class="line"><span style="color: #6A9955">// design url -- {{vbcs-cloud-url}}/ic/builder/design/khalil/1.0.0/preview/webApps/demo/</span></span>
<span class="line"><span style="color: #6A9955">// live url -- {{vbcs-cloud-url}}/ic/builder/rt/khalil/live/webApps/demo/ </span></span></code></pre></div>



<p>Get SaaS URL using JS function</p>



<p class="has-small-font-size">For any kind of link to different ERP instance for any deep link or report link to get the host name of SaaS application, configure the SaaS application as one of the backend and configure a get API</p>



<p class="has-small-font-size">Using the get API, we can use the below JavaScript code to get full URL of API, from which we can extract the exact host name</p>



<p class="has-small-font-size">Code sample for getting SaaS URL using Rest Helper</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>define(&#91;"vb/helpers/rest"&#93;, (Rest) => {
  "use strict";

  class PageModule {
    async getSaaSURL(arg1, arg2) {

      let apiURL = await Rest.get("jsonplaceholderTypicodeCom/getUsers").toUrl();

      // jsonplaceholderTypicodeCom --> this is service name
      // you can find this under Service Connections --> Overview --> Connection name 

      // getUsers --> this is endpoint name 
      // in above tab --> select endpoint and This is endpoint id 
      
      let hostName = new URL(apiURL).origin;

      console.log(apiURL); // https://jsonplaceholder.typicode.com/users
      console.log(hostName); // https://jsonplaceholder.typicode.com/
    }
  }

  return PageModule;
});
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #DCDCAA">define</span><span style="color: #D4D4D4">(&#91;</span><span style="color: #CE9178">&quot;vb/helpers/rest&quot;</span><span style="color: #D4D4D4">&#93;, (</span><span style="color: #9CDCFE">Rest</span><span style="color: #D4D4D4">) </span><span style="color: #569CD6">=&gt;</span><span style="color: #D4D4D4"> {</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #CE9178">&quot;use strict&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">PageModule</span><span style="color: #D4D4D4"> {</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">async</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">getSaaSURL</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">arg1</span><span style="color: #D4D4D4">, </span><span style="color: #9CDCFE">arg2</span><span style="color: #D4D4D4">) {</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">apiURL</span><span style="color: #D4D4D4"> = </span><span style="color: #C586C0">await</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">Rest</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">get</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&quot;jsonplaceholderTypicodeCom/getUsers&quot;</span><span style="color: #D4D4D4">).</span><span style="color: #DCDCAA">toUrl</span><span style="color: #D4D4D4">();</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #6A9955">// jsonplaceholderTypicodeCom --&gt; this is service name</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #6A9955">// you can find this under Service Connections --&gt; Overview --&gt; Connection name </span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #6A9955">// getUsers --&gt; this is endpoint name </span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #6A9955">// in above tab --&gt; select endpoint and This is endpoint id </span></span>
<span class="line"><span style="color: #D4D4D4">      </span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">hostName</span><span style="color: #D4D4D4"> = </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">URL</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">apiURL</span><span style="color: #D4D4D4">).</span><span style="color: #9CDCFE">origin</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">apiURL</span><span style="color: #D4D4D4">); </span><span style="color: #6A9955">// https://jsonplaceholder.typicode.com/users</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #9CDCFE">console</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">log</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">hostName</span><span style="color: #D4D4D4">); </span><span style="color: #6A9955">// https://jsonplaceholder.typicode.com/</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">PageModule</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">});</span></span>
<span class="line"></span></code></pre></div>



<p>Use messages or static status like APPROVED, DONE, or some ID like -1, 0, 1, or 2024 using a constant value at the application level. </p>



<p class="has-small-font-size">This will help to easily see all the values at one time and later, if there is change in actual value, we can change the value at this place with no need to change the code.</p>



<p></p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>{
  "id": "demo",
  "description": "A new VB app",
  "defaultPage": "shell",
  "constants": {
    "SUCCESS_STATUS": {
      "type": "string",
      "defaultValue": "Successfully Created"
    }
  }
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">{</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;id&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;demo&quot;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;description&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;A new VB app&quot;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;defaultPage&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;shell&quot;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;constants&quot;</span><span style="color: #D4D4D4">: {</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #9CDCFE">&quot;SUCCESS_STATUS&quot;</span><span style="color: #D4D4D4">: {</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #9CDCFE">&quot;type&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;string&quot;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #9CDCFE">&quot;defaultValue&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;Successfully Created&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">  }</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>define(&#91;"vb/helpers/rest"&#93;, (Rest) => {
  "use strict";

  class PageModule {
    async checkStatus(status, APP_SUCCESS_STATUS) {
     // pass $application.constants.SUCCESS_STATUS
      return ( status === APP_SUCCESS_STATUS )
    }
  }

  return PageModule;
});
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #DCDCAA">define</span><span style="color: #D4D4D4">(&#91;</span><span style="color: #CE9178">&quot;vb/helpers/rest&quot;</span><span style="color: #D4D4D4">&#93;, (</span><span style="color: #9CDCFE">Rest</span><span style="color: #D4D4D4">) </span><span style="color: #569CD6">=&gt;</span><span style="color: #D4D4D4"> {</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #CE9178">&quot;use strict&quot;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #569CD6">class</span><span style="color: #D4D4D4"> </span><span style="color: #4EC9B0">PageModule</span><span style="color: #D4D4D4"> {</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #569CD6">async</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">checkStatus</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">status</span><span style="color: #D4D4D4">, </span><span style="color: #9CDCFE">APP_SUCCESS_STATUS</span><span style="color: #D4D4D4">) {</span></span>
<span class="line"><span style="color: #D4D4D4">     </span><span style="color: #6A9955">// pass $application.constants.SUCCESS_STATUS</span></span>
<span class="line"><span style="color: #D4D4D4">      </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> ( </span><span style="color: #9CDCFE">status</span><span style="color: #D4D4D4"> === </span><span style="color: #4FC1FF">APP_SUCCESS_STATUS</span><span style="color: #D4D4D4"> )</span></span>
<span class="line"><span style="color: #D4D4D4">    }</span></span>
<span class="line"><span style="color: #D4D4D4">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">PageModule</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">});</span></span>
<span class="line"></span></code></pre></div>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">282</post-id>	</item>
		<item>
		<title>Getting time difference from now</title>
		<link>https://khalil232.com/javascript/258/getting-time-difference-from-now/</link>
		
		<dc:creator><![CDATA[khalil]]></dc:creator>
		<pubDate>Fri, 10 May 2024 01:54:15 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://khalil232.com/?p=258</guid>

					<description><![CDATA[Intro Working with raw timestamps is not user-friendly. Instead of showing dates like &#8220;2024-05-10 10:15:43&#8221;,we can display them in a more readable way: &#8211; 5 minutes ago&#8211; 2 days ago&#8211; in 3 months This is called relative time formatting. Example Ouput let us say today is 15-Apr-2026 and we send the input date string, the [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Intro</h2>



<p>Working with raw timestamps is not user-friendly.</p>



<p>Instead of showing dates like &#8220;2024-05-10 10:15:43&#8221;,<br>we can display them in a more readable way: </p>



<p>&#8211; 5 minutes ago<br>&#8211; 2 days ago<br>&#8211; in 3 months</p>



<p>This is called relative time formatting.</p>



<h2 class="wp-block-heading">Example Ouput</h2>



<p>let us say today is 15-Apr-2026 and we send the input date string, the api will return date readable </p>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td>Input Date String</td><td>Date Readable</td><td>Time Before / After</td></tr><tr><td>10-Apr-2025</td><td>Thursday, 10 April 2025</td><td>last year</td></tr><tr><td>20-May-2025</td><td>Tuesday, 20 May 2025</td><td>11 months ago</td></tr><tr><td>10-Mar-2026</td><td>Tuesday, 10 March 2026</td><td>last month</td></tr><tr><td>20-Mar-2026</td><td>Friday, 20 March 2026</td><td>26 days ago</td></tr><tr><td>10-Apr-2026</td><td>Friday, 10 April 2026</td><td>5 days ago</td></tr><tr><td>22-Apr-2026</td><td>Wednesday, 22 April 2026</td><td>in 7 days</td></tr><tr><td>10-May-2026</td><td>Sunday, 10 May 2026</td><td>in 25 days</td></tr><tr><td>20-May-2026</td><td>Wednesday, 20 May 2026</td><td>next month</td></tr><tr><td>10-Apr-2027</td><td>Saturday, 10 April 2027</td><td>in 12 months</td></tr><tr><td>20-Apr-2027</td><td>Tuesday, 20 April 2027</td><td>next year</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Try it yourself </h2>



<p>Enter any date and see how it converts into relative time.</p>



<iframe src="https://khalil232.com/apps/plain/date-time-ago/index.html" frameborder="0" width="100%" height="600px"></iframe>



<h2 class="wp-block-heading">How it works </h2>



<p>We calculate the difference between the current time and the given date.</p>



<p>Then we convert that difference into units like seconds, minutes, hours, days, months, or years.</p>



<p>Finally, we format it into readable text like &#8220;2 hours ago&#8221; or &#8220;in 5 days&#8221;.</p>



<h2 class="wp-block-heading">Code Example</h2>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>function getTimeAgo(dateStr) {
  const relativeTime = new RelativeTime(); // defaults to OS localen  
  let dateObj = new Date(dateStr); 
  return relativeTime.from(dateObj);
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">function</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">getTimeAgo</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">dateStr</span><span style="color: #D4D4D4">) {</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #4FC1FF">relativeTime</span><span style="color: #D4D4D4"> = </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">RelativeTime</span><span style="color: #D4D4D4">(); </span><span style="color: #6A9955">// defaults to OS localen  </span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #569CD6">let</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">dateObj</span><span style="color: #D4D4D4"> = </span><span style="color: #569CD6">new</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">Date</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">dateStr</span><span style="color: #D4D4D4">); </span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #C586C0">return</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">relativeTime</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">from</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">dateObj</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<p>We can use JavaScript to convert a date into a readable relative time format.</p>



<p>For example, &#8220;2024-05-10T01:25:14.317Z&#8221; is less readable than &#8220;7 hours ago&#8221;.</p>



<p>I have used the relative-time library to simplify this conversion:<br><a href="https://github.com/yairEO/relative-time">https://github.com/yairEO/relative-time</a></p>



<p>Full code available here:<br><a href="https://github.com/khalilahmed232/khalilahmed232/tree/main/plain/date-time-ago">https://github.com/khalilahmed232/khalilahmed232/tree/main/plain/date-time-ago</a></p>



<p>This makes date display much more user-friendly in real applications.</p>



<p>Using relative time formatting makes applications feel more modern and user-friendly, especially for feeds, comments, and activity logs.</p>



<p></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">258</post-id>	</item>
	</channel>
</rss>
