Is moment.js and moment.php the same? - javascript

I have created a js script using moment.js and I want to replicate it through a cron job. So, it will be in PHP.
So, I searched for moment.js equivalents and I found this https://github.com/fightbulc/moment.php

Technically speaking, they are not the same. The GitHub repo says:
Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
I read "inspired by" as similar in nature or close to. Otherwise, it would say something like "PHP port of Moment.js" or "PHP wrapper around Moment.js".
You should define more clearly, however, what exactly you mean by "are they the same". Do you mean the API parity? Or API compatibility? Or something else?

Well, it's not the same as it says "Inspired by the javascript library moment.js" at below mentioned sources :
1) https://packagist.org/packages/lawondyss/moment-php
2) https://github.com/fightbulc/moment.php
which means it is developed by taking the reference of the javascript library moment.js , it may contain the same functionality as well as it's own (newly added than the javascript moment.js).
You can compare the two from downloading/checking the documentation from different sources as below :
1) for moment.js you can check here : https://momentjs.com/
2) for moment.php you can check here : https://github.com/fightbulc/moment.php OR
https://packagist.org/packages/lawondyss/moment-php

Related

Making a Native ELM module with Moment.js

I've been playing around with Elm for a couple of days and I wanted to make a port of Moment.JS, since I've seen a lack of libraries for what I wanted, and Moment just has everything that I need.
The thing is that I always face the same error. I have Moment.JS in my Native folder (it is named MomentJS.js) and another file called Moment.js (my wrapper). The problem is that when I call moment in Moment.js, I get an error saying that moment is not defined.
I've tried to import MomentJS.js in my elm file as well, before and/or after Moment.js. I've also tried to copy the whole JS into Moment.js and add my wrapper at the end of it. None of this things worked. You know what could I do? I've been looking for similar repos on the internet but I've never seen a module that has a wrapper and another JS file just for the native library.
This is my Moment.js code:
var _user$project$Native_Moment = (function() {
var moment = require('moment');
var format = function ( format, date ) {
return moment().format();
}
return {
format: format
};
})();
and my Moment.elm code:
module Moment exposing (format)
{-| A module desc
#docs format
-}
import Native.MomentJS
import Native.Moment
{-| Call the default `Moment.js` format method
-}
format : String -> String -> String
format fm dt = Native.Moment.format fm dt
The last thing that I tried was to download Moment from npm, copy its folder from the node_modules folder to my Native folder and do moment = require('moment') but I got TypeError: fun(...) is not a function.
Any suggestions?
After some digging, what you are looking to do is completely possible yes! :) However, it won't be a simple copy paste. Look at the source you posted here, it will require mapping every function to the native elm functions, i'd recommend starting small with this conversion.
First, Get a simple hello world Native example work, see here
Secondly, add in some of the simpler functions from moment.js one by one, i'd recommend starting with moment\src\lib\format\format.js
Lastly, I know this isn't what you want to hear, but if you really want to write javascript in elm, maybe Elm isn't what you are looking for? I really can't imagine converting an entire library similar to Moment.js would be simpler than creating your own Elm library inspired by Moment.js
Either way, best of luck! Seems like a fun challenge either way :)
There are two supported ways for Elm and JavaScript to talk to each other: ports and flags. Both are asynchronous and will be awkward for your needs.
https://guide.elm-lang.org/interop/javascript.html
Should you write native code? Elm's creator says no.
So the best path forward is to use one of the existing time/date libraries or write what you need yourself.

How to load timezone files with timezone-js without Fleegix.js?

I want to use timezone-js in my app, but I'm not Fleegix.js, which "just works". The readme says to look in the spec file for an example, but it looks like that uses Node.js stuff. Is there a way to make a load for Jquery or just raw JS or something?
I got confused on those docs also. It's not quite clear, but jQuery support is already built in. You just have to set async to false to get it to work. Not sure why - since ajax is async anyway - but that's the flag to set to get it to work with jQuery. No other wireup is needed.
timezoneJS.timezone.zoneFileBasePath = 'scripts/tz';
timezoneJS.timezone.init({ async: false });
Also - there are other libraries that do the same thing. You may find one of these more appealing.

Zend Framework Date Time Picker

I'm a real newbie in programming and finally got the ZendX Jquery to work. However, I would like to include a date time picker, and found an option at http://www.binpress.com/app/zfdatetimepicker/85 . However, the documentation is not complete and I would really want to set it up correctly. Can anyone help me with the steps required to do so? I tried setting it up and got the error " Object doesn't support property or method 'datetimepicker'". Thanks.
It sounds like you need to include the jquery UI script files. Looking at his demo, it is pulling in jQuery UI 1.8.21 from jquery's 'code' servers. I also know that without the UI component included, you will get the error message Object doesn't support property or method 'datepicker' when you do something like $('#myDate').datepicker. So I'm assuming you're just missing the correct script includes.
I've not used zend-framework at all, so I might be missing something on that side.

libphonenumber standalone (without masses of google dependencies)? Alternate lib?

I am looking at using http://code.google.com/p/libphonenumber/ for a well-established project. Today the project does not use Google's libraries for JavaScript, favoring jQuery, jQueryUI, requirejs, and so on.
libphonenumber looks awesome ... except that the javascript version (svn co http://libphonenumber.googlecode.com/svn/trunk/javascript/ libphonenumber-js) is laced with goog.require calls. If one runs the demo (libphonenumber-js/i18n/phonenumbers/demo.html if you checked out as suggested) it pulls in tons of google libraries from closure-library.googlecode.com :
GET base.js
GET deps.js
GET error.js
GET string.js
GET asserts.js
GET array.js
GET useragent.js
GET browserfeature.js
GET tagname.js
GET classes.js
GET math.js
GET coordinate.js
GET size.js
GET object.js
GET dom.js
GET json.js
GET util.js
GET descriptor.js
GET fielddescriptor.js
GET message.js
GET serializer.js
GET objectserializer.js
GET stringbuffer.js
GET lazydeserializer.js
GET pbliteserializer.js
I believe if I compile this using the closure compiler ("If you give the use_closure_library parameter a value of true, the compiler looks for goog.require() statements in the source code and supplies the Closure Library code requested by any such statements.", https://developers.google.com/closure/compiler/docs/api-ref) I can cut down the raw number of requests, but this still seems like a rather excessive amount of content for a phone number parser, even a full-featured one.
My question has two possible answers:
A way to use libphonenumber in JavaScript without having to pull in all the Google JavaScript base libraries
An alternate standalone (as in doesn't have dozens of dependencies) first-class phone number processing library with both JavaScript and Java implementations
Any and all suggestions most appreciated.
I've got a custom build (currently 220KB) that I use for my International Telephone Input plugin, with plenty of helper functions exposed. Read the source for details.
You can also use my lib.
https://github.com/Gilshallem/phoneparser
Its only got one method but you can do a lot with it
parsePhone("12025550104");
result: { countryCode:1, areaCode:202, number:5550104, countryISOCode:"US" }
Here are two implementations of Google libphonenumber in JavaScript that have zero dependencies and are implemented in a single file. I've used Nathan Hammond's version without issue but it is not on NPM. Rui Marinho's version is on NPM.
https://github.com/nathanhammond/libphonenumber
https://github.com/ruimarinho/google-libphonenumber
I just spent 2 days figuring this out. For now, anyway, you can download a minified version of libphonenumber-js from here
drop it in place, with the usual
<script type="text/javascript" language="javascript" src="/static/js/libphonenumber-js.min.js"></script>
and get busy coding!
<script>
$(".phone-format").keyup(function () {
var val_old = $(this).val();
var newString = new libphonenumber.AsYouType('US').input(val_old);
$(this).focus().val('').val(newString);
});
</script>

DateJS missing functions

I stumbled on DateJS, Javascript opensource library for date functions. Looks pretty cool.
What is puzzling me is, in the documentation they talk of some functions but those functions are unavailable in the main datejs file, eg.
Example of missing/hidding functions include
Date.today().first().monday()
I get the error, object Date has no method first() error
Any idea how this library works?
Gath
Finally i got the correct version found here. I wish DateJS web site can point the main download to this link.
Thanks all.
It works fine for me using your example. Have you made sure that the date.js include has loaded before using it; try putting your call in your onload function rather than being called immediately.

Categories