GithubHelp home page GithubHelp logo

aaronlumsden / tidytime.js Goto Github PK

View Code? Open in Web Editor NEW
195.0 13.0 25.0 40 KB

A jQuery plugin, that provides a more friendly way of displaying time updates to users!

Home Page: http://git.aaronlumsden.com/tidytime.js/

JavaScript 100.00%

tidytime.js's Introduction

tidyTime.js

A jQuery plugin, that provides a more friendly way of displaying time updates to users!

tidyTime.js takes any regular time and changes it into more human friendly dialogue such as "It's just gone noon. It's quarter past 8 in the evening, it's nearly half past 4 in the afternoon, it's just gone 25 to 6" and more. By adding additional text before and after the time you are able to create powerful friendly interaction with users.

tidyTime.js works best with dynamic websites and apps and can be used as a stand alone clock. Here are some examples.

							</tr>
							<tr>
								<td><code>5:45</code></td>
								<td>becomes</td>
								<td>"Wakey wakey! It's a quarter to 6 in the morning"</td>
							</tr>	
							<tr>
								<td><code>14:29</code></td>
								<td>becomes</td>
								<td>"It's nearly half past 2"</td>
							</tr>
							<tr>
								<td><code>16:55</code></td>
								<td>becomes</td>
								<td>"You recieved this message at 5 to 5"</td>
							</tr>
							<tr>
								<td><code>16:33</code></td>
								<td>becomes</td>
								<td>"It's 27 minutes to 5. You're gonna be late!"</td>
							</tr>
							<tr>
								<td><code>20:00</code></td>
								<td>becomes</td>
								<td>"It's 8 o'clock and 3 of your friends shared this on Twitter"</td>
							</tr>
							<tr>
								<td><code>12:01</code></td>
								<td>becomes</td>
								<td>"It's just gone 12 noon. Lets create some music!"</td>
							</tr>

							<tr>
								<td><code>13:45</code></td>
								<td>becomes</td>
								<td>"This blog was posted at a quarter to 4"</td>
							</tr>

						</tbody>
					</table>

##..:: Getting Started

Include the relevant files

Firstly include jQuery and tidyTime.js files.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="tidyTime.js"></script>

Instantiate the plugin

Create an element such as a div or span and add a class or ID of your choice.

<span class="tidyTime"></span>

In it's most basic form tidyTime can be actioned with no options passed and will just display the current time in tidyTime format.

$(document).ready(function ($) {

   $('.tidyTime').tidyTime();	

});

If you want to instantiate the plugin with options then you can do so like:

$('.tidyTime').tidyTime({
    	time: '08:15',
		before:'It\'s ',
		after:' and I\'m feeling good!',
		periodOfDay: true,
		callback:tidyTimeFunction
	});

###Options

08:15 becomes "Howdy Aaron! It's a quarter past 8"
Variable Default Value Description
time the current time The time that you would like to convert. In format mm:hh
before The text string to be used before tidyTime
after The text string to be used after tidyTime
periodOfDay Whether to append the period of day to tidyTime.
Phrases include 'in the morning','in the afternoon','in the evening','at night'
callback The name of the function that you would like pass as a callback once the time has been updated. On return three values are passed back to your function. the element, time and tidyTime
###..:: Using tidyTime.js as a Clock tidyTime can be used as a clock. Simply instantiate it when the page is first loaded and then create a setInterval to update. The current time will automatically be calculated within the plugin.
//HTML
<span class="tidyTime"></span>

//Jquery
var tidyTime = $('.tidyTime');
tidyTime.tidyTime({
    	before:'Hey dude! It\'s ',
		after:' and I\'m feeling good!'
	});

setInterval(function(){

	tidyTime.tidyTime({
		before:'Hey dude! It\'s ',
		after:' and I\'m feeling good!'
	});

},30000);

tidytime.js's People

Contributors

aaronlumsden avatar

Stargazers

Carlos A. Ruíz A. avatar condor avatar Pulkit Kathuria avatar Vaughan James avatar Jeff Morris avatar JJ Ying avatar  avatar Arlan Galvez avatar Elon Zito avatar  avatar Adam Farnsworth avatar Axelaredz avatar oConner avatar Bryan Blanchot avatar  avatar Angus H. avatar TuNA avatar Yury Tsukerman avatar Eugene Mutai avatar  avatar Newerton avatar Daniel McClintock avatar Minho Ryang avatar Milan T avatar send2vinnie avatar Nickolay Stolyarov avatar Enoi Barrera Guzman avatar Richard G Chillington III avatar Max Khrichtchatyi avatar A Z 1 B avatar 李茂盛 avatar  avatar James Benner avatar Omar avatar  avatar Caesar73 avatar Juha Tauriainen avatar Lari Hoppula avatar Michael Mior avatar Lakatos Tibor avatar Ali Halabyah avatar Dave Onkels avatar Chris Yee avatar  avatar Irfaq Syed avatar Riccardo Bartoli avatar Ozan Kilic avatar Ger Hobbelt avatar Arturo Guerrero avatar Kawsar Ahmad avatar Marco Pedraza avatar Adi Rao avatar QETHAN avatar Ahmed Refaat avatar suhendro avatar Frank Mullenger avatar  avatar Michał Ochman avatar 像树一样成长! avatar Hao Wu avatar Wyntau Lau avatar Desen Meng avatar  Vivek Rp avatar Andrew Turner avatar Dermot McGuire avatar Steve O. avatar Tristan avatar Luiz Eduardo de Oliveira Fonseca avatar Marcelo Santos avatar Leon Barrett avatar Joe Ketterling avatar Stefaney Roberts avatar James Blackwood avatar Henri Bouvier avatar Henrik Westphal avatar wani avatar Alex avatar gaurav patel avatar janily avatar Manikanta Gade avatar Brandon Burkeen avatar Sasha Beg avatar Frido Koch avatar Andrei Horak avatar gclove avatar Ivan Ionut avatar Miguel avatar Sungmyung Lee avatar Adnan Topal avatar Shoora avatar Jordan Cauley avatar Malinthe Samarakoon avatar Weirong Yang avatar Ryan Holm avatar  avatar Reuben avatar netop://ウエハ avatar Andrew G. avatar __FresHmaN avatar Gyorfi Sandor avatar

Watchers

Omar Dixon avatar Jeremy Moore avatar Luiz Eduardo de Oliveira Fonseca avatar send2vinnie avatar Andrew G. avatar coletree avatar Michal Kechner avatar James Cloos avatar  avatar  avatar  avatar mtbink.com avatar Arlan Galvez avatar

tidytime.js's Issues

Simplifying fomartTimeHourse

Hi aarondo,

I have one question about your fomartTimeHourse function.
What is the use of return h < 10 ? h : h;?
You check if h is less than 10 then return h, but if that is false, it is still returns h, better shorten that to just return h;.

Here is the updated function:

            function fomartTimeHourse(twenty4h) {

                var h = twenty4h % 12;


                if (h === 0) h = 12;

                return h;

            }

Here is my version in case you are interested:

            function fomartTimeHourse(number) {
                var n = parseFloat(number);
                n = n % 12;
                return n == 0 ? 12 : n;
            }

Thanks,
mtbink.com

If the time is 09:59 AM it is currently saying nearly 9 o'clock

Hi aarondo,

Let say the current time is 09:59 AM, then your function will returns nearly 9 o'clock in the morning whereas it should be nearly 10 o'clock in the morning.
We should use the next hour, 10 not the current hour 9.

Browsing through your code I think you missed one validation here.
This is for the case where m == 59.
The original script is:

            } else if (m === 0 || m == 1 || m == 59) {
                if (m == 1) {
                    justgone = 'just gone ';
                } else if (m == 59) {
                    justgone = 'nearly ';
                }
                $tense = justgone + h + ' o\'clock';
            }

we have to use the value of h + 1 somewhere in between and make sure that the value of h + 1 is in 12-hour format.
You have already created the function fomartTimeHourse to transform the hour to 12-hour format, so I think you can add the line fomartTimeHourse(h + 1);.
Here is my current fix:

            } else if (m === 0 || m == 1 || m == 59) {
                var hourToUse = h;
                if (m == 1) {
                    justgone = 'just gone ';
                } else if (m == 59) {
                    justgone = 'nearly ';
                    hourToUse = fomartTimeHourse(h + 1);
                }
                $tense = justgone + hourToUse + ' o\'clock';
            }

Thanks,
mtbink.com

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.